Results 1 to 6 of 6

Thread: Error - java.lang.NumberFormatException

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Error - java.lang.NumberFormatException

    Hello,
    I have done a code but the program gives me an error and I have no idea about the error what I am getting.
    here s the error
    Code:
    java.lang.NumberFormatException
    If you have any idea the please explain me what exactly is this error all about. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Error - java.lang.NumberFormatException

    Hello,
    I think this is clear, however, you may be trying to convert an int (integer) an empty string, that is why you are getting this error
    Code:
    java.lang.NumberFormatException: For input string: ""
    If you want that helps you, post the code for the actionPerformed method of the class Calculator. Hope you have understood the error and you wil correct it in the code correspondingly. If you need any more help the you may ask.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Error - java.lang.NumberFormatException

    Hello,
    We must learn to read a stacktrace?
    Code:
    java.lang.NumberFormatException: For input string: ""
    The string "could not be converted into numbers.
    Code:
    at Calculator.actionPerformed(Calculator.java:)
    and the problem comes from line that is mentioned in the error of file Calculate.java source code. In short we use the method Integer.parseInt () without try / catchAnd as you pass it an invalid value (empty string), it goes back an exception. Hope you get the point.

  4. #4
    Join Date
    Dec 2009
    Posts
    204

    Re: Error - java.lang.NumberFormatException

    Hello,
    For the try / catch I think you never used the syntax properly, otherwise you can not find "that must be converted to int and something like this
    Code:
    a = Integer.parseInt(fields.getText());
    I think this is what you are trying to use in your code and because of this you are getting the error, if you are using something like this then please comment on it and then try to run that is compile the program.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Error - java.lang.NumberFormatException

    Hello,
    The problem is simple: One of your fields is empty so the appeal champs.getText () returns "". Then Parse fails and launches the exception. As we told you use try catch to find the error / avoid the crash program.
    Code:
    try
    {
    a = Integer.parseInt (champs.getText ());
    
    / / Process a normal
    
    }
    catch (NumberFormatException e)
    {
    / / Here you can write code for error handling, for example e.printStackTrace () to display the error in your error console or a beast System.out.println ( "Goal 1 planted);
    }

  6. #6
    Join Date
    Nov 2009
    Posts
    359

    Re: number format exception

    Hello,
    I do not know your program, but the user has the right to change fields? If yes, be careful now, it could very well clear a field and replant a new tone program. Or he could write the letters or numbers you waiting for . When working on a GUI, you must always consider that the user is either incompetent or malicious, and so anything that provides must be tested before being used.

Similar Threads

  1. Replies: 5
    Last Post: 27-08-2011, 10:36 PM
  2. Replies: 5
    Last Post: 15-12-2010, 07:18 PM
  3. Error Java.lang.OutOfMemoryError
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 04-03-2010, 12:42 PM
  4. Error message: Uncaught Exception java.lang.error
    By Rum in forum Portable Devices
    Replies: 5
    Last Post: 06-01-2010, 01:59 PM
  5. Java.lang.OutofMemory.Exception error
    By Unnat in forum Software Development
    Replies: 3
    Last Post: 07-05-2009, 11:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,833,317.94515 seconds with 16 queries