Search code examples
javaexceptionnumberformatexception

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.


Solution

  • 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.