This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java string problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java string problem" Watch "Java string problem" New topic

Java string problem

Martin Ctys

Joined: Mar 11, 2013
Posts: 2

I declared the int previously, and set it as "none". Inside the object, I also set MonsterName as none, or it would say error: not a statement.
Okay, that got rid of the compiler error. I made a setter and getter method for the object to return the MonsterName:

No compiler errors so far.
A test drive:

Everything compiles correctly, but as the output I'm getting "none" after the name ( output: Name none )
I really need help, thank you for your time! I removed some irelevant code pieces, but if you want the full code, just tell me.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 641

do you see something wrong here?

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Martin Ctys wrote:

You have the assignment backwards. You need to make the variable being assigned to on the Left side, and the one being assigned from on the Right. This is a common mistake, and one I like to prevent by making the parameters to methods final:

If you do that then the compiler complains and you know exactly where the problem is!

Martin Ctys

Joined: Mar 11, 2013
Posts: 2
Thanks, you guys are great! So the parameter always goes after?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 641
So the parameter always goes after?

don't remember it this way, remember that for assignment operator (=) the left side variable receives the value from right side variable (or constant or literal ).

Jeff Verdegan

Joined: Jan 03, 2004
Posts: 6109

It seems that you know the order, since you wrote
in your code.

If you had tried instead, it would have been a compile error.

So, doing MonsterName = XName is exactly the same as doing MonsterName = "none". In both cases, you're taking the reference value in the RHS expression and copying it into the LHS variable.
I agree. Here's the link:
subject: Java string problem
It's not a secret anymore!