Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.NumberFormatException: For input string: "3291105000"

Why is this happening? The string I'm parsing looks clearly like an int. The program is reading from a file, and I know that it's working for the most because this number is way down the list. Any ideas? Also, the program is parsing ints larger than 2.2 billion, so I don't know if it's a size issue.

like image 570
user1451840 Avatar asked Jan 16 '23 10:01

user1451840


2 Answers

A signed 32-bit int can only be as large as 2^31, or 0x7FFFFFFF (2,147,483,647). You'll need to use a bigger datatype. long will get you up to 2^63. Or the BigInteger class will get you an arbitrary sized integer.

like image 193
Jonathon Reinhart Avatar answered Feb 12 '23 12:02

Jonathon Reinhart


int can have a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive), Your number(from string) falls out of the range

Use long instead Long.parseLong(3291105000) would work for you

like image 23
jmj Avatar answered Feb 12 '23 12:02

jmj