aspose file tools*
The moose likes Beginning Java and the fly likes Function problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Function problem" Watch "Function problem" New topic
Author

Function problem

Sacha Crompton
Greenhorn

Joined: Nov 23, 2004
Posts: 5
I have a function:
void NumberPressed(String x)
{
Display.setText(x);
}

Which I am trying to call with:
NumberPressed(toString(Count + 1));

But I keep getting this error when compiling:
toString() in java.lang.Object cannot be applied to (int)
NumberPressed(toString(count + 1));

What am I doing wrong?

Thanks
Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97
Hi,

toString() is a method which should be reference via it's class. If you want an int to be returned as a string you us the Integer class to reference the toString method in this class. Integer.toString(someNumber).

toString() is static which is why you don't need a instance variable to refer to the method. All that is needed is the class.

P.S. if you want to do more toString()'s for different primitive data types look at the documentation for java.lang.


Jimmy Die
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
SachaC,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request that display names follow the pattern FIRST_NAME + SPACE + LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
Don't get me started about those stupid light bulbs.
 
subject: Function problem