• Post Reply Bookmark Topic Watch Topic
  • New Topic

setName(char) in method cannot be applied  RSS feed

 
Rich McStone
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I have been learning java for a while, and I tried to write a simple program.


And I got this error :
javac method.java
method.java:18: setName(char) in method cannot be applied to (java.lang.String)
                cat.setName("╨С╨░╤А╤Б╨╕╨║╤Б╤В╨╡╤А");
                   ^

I can't really understand what is causing that, the structure of code looks similar to what is in the book.

I tried reading about this problem somewhere else, but I didn't understand what they were talking about.
So I came here :B
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The setName() method takes a primitive char type. You passed it a String type. A char type is not the same as a string type -- in fact, a char is not even an object.

Also, you seems to have "methodd" and "method", which are different, and which I assume are typos...

Henry
 
Rich McStone
Greenhorn
Posts: 22
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I didn't know the difference between char and string types.

Also, you seems to have "methodd" and "method", which are different, and which I assume are typos...


I was thinking that class name "method" was messing up with compiler, so i changed that a little bit, and I have forgotten to change name there :P

Now that is working just fine, I'll get back to messing with program, thanks for helping!
Also, can I post questions in Beginning Java forums if I don't find solution somewhere else?
Because i usually can't quite understand explanations or how to solve the problem.
 
John Joe
Ranch Hand
Posts: 443
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rich McStone wrote:Also, can I post questions in Beginning Java forums if I don't find solution somewhere else?
Because i usually can't quite understand explanations or how to solve the problem.

Sure, you can 
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rich McStone wrote:. . . can I post questions in Beginning Java forums if I don't find solution somewhere else?  . . .
That is the sort of thing the BJ forum is there for. The more information you provide the better an answer you will get. Something like
Why can't I do arithmetic with i++?
will not get anything like as good an answer as
I am trying arithmetic with i++ and can't understand why the result is 1 too small. They said on website XYZ that there is a delay in i++, but it says on website PQR that ++ has a high precedence and I can't understand the difference.
The latter will allow us to compare the two answers. Experience also shows the person A and person B will try their hardest to explain it, and you don't understand the explanation. Then person C comes on the scene and their one‑line explanation seems to make everything crystal clear.

Also always tell us (and the other people) if you ask the same question on two websites.

By the way: any explanation of i++ saying there is a delay is inaccurate.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!