Results 1 to 3 of 3
  1. #1
    alexandra12 is offline Member
    Join Date
    Jul 2011
    Rep Power

    Default toString() giving errors


    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

    Java Code:
    public int getNum(){
    		return num;
    	public void setNum(int num) {
    		this.num =(num);
    Here is the code calling for the setNum function

    Java Code:
    String tmpString;
    As you can see I have tried it a few ways - but I am getting errors

    sample error from Eclipse
    at java.lang.Integer.parseInt(
    at java.lang.Integer.parseInt(

    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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    On vacation
    Rep Power

    Default 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.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: toString() giving errors

    Java Code:
    String tmpString;
    // ...
    Umm... that compiles?
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. while loop tries 20 times before giving up
    By JMAsterson in forum New To Java
    Replies: 3
    Last Post: 04-10-2012, 10:02 PM
  2. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  3. Replies: 3
    Last Post: 03-08-2009, 02:51 AM
  4. Giving Warning
    By tanmoy.b81 in forum New To Java
    Replies: 1
    Last Post: 12-24-2008, 10:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts