• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help on methods  RSS feed

 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why isn't the add method working?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's "not working" mean? What is happening? How is it unexpected? Please read ItDoesntWorkIsUseless
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method call is underlined saying cannot invoke add(int, int) on the primitive type int.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right. Primitive types do not have methods.

You defined an add() method on the Formulas class; did you somehow expect that would add a method to ints?
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your post does not help me understand how to solve the problem. If I knew what you were talking about, I would not have posted in the Beginning Java forum to begin with. So, I guess we're at an impass. Again.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's hardly the best way to ask for clarification.

Object have methods. Primitives are not objects and do not have methods. So there is no add() method (or any other method) on an int that you can call; hence the error message.

If you defined an add() method in the Formulas class, you need an instance of a Formulas object in order to call its add() method.
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, well your post did help a little. And then I figured it out. Honestly though, if EYE were helping me, I would say, "Use Formulas.add because your method is in there" or something along those lines. I don't do well with Socratic learning, so it's frustrating when people try to make me guess at what I'm supposed to do.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will be sure in the future not to make posts that help you a little.
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I will be sure in the future not to make posts that help you a little.


Well maybe if you just speak English, instead of Java, then it's more helpful. As a beginning programmer, I don't understand Javaspeak. So if you word all of your answers in Javaspeak, and don't dumb it down at all, then you're simply not helping. I'm sorry that you don't see that, and that you are so set in your ways that you will not compromise as a helper. Thanks for trying to help though.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is very difficult for anyone to figure out what level of learning some other person is. If you did not understand something (which is, if you forgive the pun, understandable ) it would have helped if you had posted something on the lines of "Umm I am not sure what you mean by that. Perhaps you can rephrase?"

One of the best things about the Ranch is that it's a really friendly place and everyone is eager to help out.
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey thanks Maneesh. I guess I've just run into similar situations with programmers before and it seems they always want to give you a high level understanding explanation. I'll try your approach next time.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!