Results 1 to 3 of 3
Thread: toString() giving errors
- 06-12-2012, 01:58 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 32
- Rep Power
- 0
toString() giving errors
Hello,
I am wondering if someone can guide me as to what I am doing wrong in my code.
I have a String and an int variable. I need to pass the int variable into the string variable - so I need to parse the int variable from an int into a string.
Here is part of my code
//getter - setter
Here is the code calling for the setNum functionJava Code:public int getNum(){ return num; } public void setNum(int num) { this.num =(num); }
As you can see I have tried it a few ways - but I am getting errorsJava Code:String tmpString; if(qName.equalsIgnoreCase("num")){ north.setNum(Integer.toString(tmpString)); north.setNum(String.valueOf(num)); north.setNum(String.valueOf(Integer.toString(tmpString))); }
sample error from Eclipse
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:511)
I am also getting different errors - saying to change from int function to a string function which I dont want to do.
Any advice would be greatly appreciated.
- 06-12-2012, 02:43 AM #2
Re: toString() giving errors
You left off the first line of the error message. What was the exception?
The setNum() method takes an int value as an argument. Do any of the methods you tried return an int value?
The Integer class has a method to convert a String to an int. The eclipse error message shows you have tried it.
What was the value of the String you tried to convert?If you don't understand my response, don't ignore it, ask a question.
- 06-12-2012, 04:41 AM #3
Re: toString() giving errors
Umm... that compiles?Java Code:String tmpString; // ... north.setNum(Integer.toString(tmpString));
Get in the habit of using standard Java naming conventions!
Similar Threads
-
while loop tries 20 times before giving up
By JMAsterson in forum New To JavaReplies: 3Last Post: 04-10-2012, 10:02 PM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
What is the difference between Semantic Errors and Logical Errors?
By tlau3128 in forum New To JavaReplies: 3Last Post: 03-08-2009, 01:51 AM -
Giving Warning
By tanmoy.b81 in forum New To JavaReplies: 1Last Post: 12-24-2008, 09:21 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks