silly question

hello, i have a question,

as you konw "drawString" method. when I write the method as" g.drawString (example,25,25)" it gave me error message as can not resolve smybol. however if i changed it to "g.drawString("example"+example,25,25) it works. can I ask what is the different between them?

hope i explain it clear

[334 byte] By [ritchie_lina] at [2007-11-27 11:45:11]
# 1

What type is your variable example?

floundera at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...
# 2

Edit: Nevermind. I misread the question.

Message was edited by:

jverd

jverda at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...
# 3

Obviously my question was extremely silly and did warrant an answer.

floundera at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...
# 4

> hello, i have a question,

> as you konw "drawString" method. when I write the

> method as" g.drawString (example,25,25)" it gave me

> error message as can not resolve smybol. however if

> i changed it to

> "g.drawString("example"+example,25,25) it works. can

> I ask what is the different between them?

drawString takes a String for its first arg, I guess. Your example variable is not a String.

If you read the whole error message, you'll see that the symbol that doesn't exist is the method you're trying to call--a drawString that takes whatever type your example variable is.

Learn to read error messages fully and carefully.

On the other hand, whenever you some string + something, a String is created from the something (by String.valueOf, I think) and added to the other string.

You can make the first one work by using String.valueOf(example) instead of just example.

jverda at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...
# 5

the word" example" I have declare it as "double" , does it matter?

ritchie_lina at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...
# 6

> the word" example" I have declare it as "double" ,

> does it matter?

Depends what you mean.

It matters to the compiler that you're passing a double where it expects a String. That's why you get the error.

It doesn't matter to my explanation as to why you see the behvaior your do. The behavior would be the same and my explanation would hold for any non-String type that you declare example to be.

jverda at 2007-7-29 18:00:19 > top of Java-index,Java Essentials,New To Java...