Search code examples
javadoublenumberformatexception

Exception- java.lang.NumberFormatException: For input string: " 000000000"


I have this return after a query in database, I dont know what exactly means.

Caused by: java.lang.NumberFormatException: For input string: " 000000000"

Someone help me please. Thanks


Solution

  • From the Javadoc for NumberFormatException

    Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

    In your case you have a space in the number, you can trim it with trim()

    How i can do this in number?

    Before attempting to parse the number you need to make sure it is formatted as a number.

    e.g.

    String s = " 00000000";
    int n = Integer.parseInt(s.trim()); // remove leading/trailing spaces.