rr11
rr11

Reputation: 55

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

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.

Upvotes: 2

Views: 219

Answers (2)

Alex F
Alex F

Reputation: 81

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.

Upvotes: 2

Juvanis
Juvanis

Reputation: 25950

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

Upvotes: 1

Related Questions