File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java string problem" Watch "Java string problem" New topic
Author

Java string problem

Martin Ctys
Greenhorn

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 MonsterObject.java:17: 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
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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!


Steve
Martin Ctys
Greenhorn

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 ).

-P
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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: http://aspose.com/file-tools
 
subject: Java string problem