Search code examples
javanumberformatexception

java.lang.NumberFormatException when trying to parse a regular valid integer


What is going on here?

This is the value of checkSum = "2367122119". And I would like to parse this number as an integer value like this:

int ipAddressAsInt = Integer.parseInt(checkSum.trim());

As a result I'm getting the following exception:

java.lang.NumberFormatException: For input string: "2367122119"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:583)
    at java.lang.Integer.parseInt(Integer.java:615)
    at com.example.servlets.RDServlet.doPost(RDServlet.java:40)
    ...

Also, the same happens if I try Long.parseLong(checkSum).

How is that possible?


Solution

  • the number is to big for an int:

    @Test
    public void testMaxInt() {
        System.out.println(Integer.MAX_VALUE);   
    
        System.out.println(Integer.MIN_VALUE);   
    
      }
    

    2147483647

    -2147483648