File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Function problem

 
Sacha Crompton
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic