Exception in thread "main" java.lang.NumberFormatException: For input string that's not null or empty

Viewed 161

getting an Exception in thread "main" java.lang.NumberFormatException: For input string: "8801609054" even though it can properly read the format.

I'm using

Integer.parseInt("8801609054");

to do this. I've found people with similar error usually had null or empty values but this one has a value so I'm not sure where the error is coming from.

2 Answers

The number you passed as a string is too large. The largest integer allowed is Integer.MAX_VALUE (2147483647). Maybe you should work with BigDecimal instead.

8801609054 is larger than the maximum integer value (primitive int) in Java. You can compare it with Integer.MAX_VALUE and confirm.

Related