Exception in thread "main" java.lang.NumberFormatException: for input line: "3291105000"

Why is this happening? The line I'm processing looks explicitly like int. A program reads from a file, and I know that it works the most because it is a number down the list. Any ideas? In addition, the program analyzes ints over 2.2 billion, so I don’t know if there was a problem with the size.

+4
source share
4 answers

A signed 32-bit int can reach 2 ^ 31 or 0x7FFFFFFF (2 147 483 647). You will need to use a larger data type. long will deliver you up to 2 ^ 63. Or the BigInteger class will give you an arbitrary integer value.

+7
source

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

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

+2
source

Use long , which can contain integers of 64 bits.

  • int can store integers up to ~ 2 billion
  • long can contain integers up to ~ 9e18
0
source

Like others, a number clearly goes beyond the int range and therefore you get an exception.

4 bytes signed (two additions). -2,147,483,648 to 2,147,483,647. Like all numeric types, ints can be added to other numeric types (byte, short, long, float, double). When dumping losses are performed (for example, int by byte), the conversion is performed modulo a length of a smaller type.

0
source

All Articles