File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Function problem

Sacha Crompton

Joined: Nov 23, 2004
Posts: 5
I have a function:
void NumberPressed(String 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?

Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97

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

Joined: Dec 10, 2001
Posts: 7023

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]
I agree. Here's the link:
subject: Function problem
It's not a secret anymore!