aspose file tools*
The moose likes Beginning Java and the fly likes toString Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toString " Watch "toString " New topic
Author

toString

Timo Lumme
Greenhorn

Joined: Jan 05, 2007
Posts: 20
hi
im confused with toString methods
i fetch data int type and need converted on fly to string to the gui


W Pearce
Ranch Hand

Joined: Jan 06, 2009
Posts: 32
Really all you have to do here is change the return type in the signature of getMaxID to String HOWEVER if you want to comply with javabeans standards, your method signature should really be public int getMaxID() with no arguments, you can rely on your setMaxID(int s) method to set the value. You should just call your toString() method from your GUI - that will return your LottoMaxID represented as a String object the way you have coded it here.


SCJP 6, SCWCD 5
Timo Lumme
Greenhorn

Joined: Jan 05, 2007
Posts: 20
good but i get when trying it
i get error int cannot be dereferenced

LG.button4.setText(LD.getMaxID().toString());

this so simple stuff but manage to screw anyway, arrgh ..
W Pearce
Ranch Hand

Joined: Jan 06, 2009
Posts: 32
try changing LG.button4.setText(LD.getMaxID().toString()); to LG.button4.setText(LD.toString());
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Timo:

In java, primitives are not objects. This line is causing the problem:



Your getMaxID() method returns an int, which is a primitive. If you want to convert it to a String, try this:


Note, I'm using the Integer class, which is different from an int primitive.

John.
Timo Lumme
Greenhorn

Joined: Jan 05, 2007
Posts: 20
Big Thank You
(i wish i would have your java brains/knowledge.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: toString
 
Similar Threads
Question related to Enum
Covariant doubt
Sorting a HasMap by Values
Can we redeclare a class
Exception Question help