Reputation: 16651
I am getting the following exception when i get execute the following code
Integer.parseInt(1357679682162)+1
INFO | jvm 1 | srvmain | 2013/01/08 22:22:09.496 | Caused by: java.lang.NumberFormatException: For input string: "1357679682162"
INFO | jvm 1 | srvmain | 2013/01/08 22:22:09.496 | at java.lang.NumberFormatException.forInputString(Unknown Source)
INFO | jvm 1 | srvmain | 2013/01/08 22:22:09.496 | at java.lang.Integer.parseInt(Unknown Source)
INFO | jvm 1 | srvmain | 2013/01/08 22:22:09.496 | at java.lang.Integer.parseInt(Unknown Source)
Upvotes: 0
Views: 351
Reputation: 2404
Check yourself with below code and use the feasible type for your solution.
System.out.println(Integer.MAX_VALUE);
System.out.println(Long.MAX_VALUE);
Upvotes: 0
Reputation: 311
The number is too long.
Integer is supposed to be less than 2 ^31 = 2147483646
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html
Upvotes: 0
Reputation: 1188
Isn't the number too big to fit in an int? The range of int in java is from -2,147,483,648 to 2,147,483,647. Maybe you should use parseLong instead.
try
Long.parseLong(1357679682162)+1
Upvotes: 0
Reputation: 6255
Java Integer Max value is 2147483647.
And you are trying to parse 1357679682162.
Upvotes: 0
Reputation: 14277
That number is too big for integer. Integer is 32 bit value, so max value is 2,147,483,647. Try using long instead.
Upvotes: 3
Reputation: 3274
The number you are passing is outside the range of integer which is from -2,147,483,648 to 2,147,483,647
Upvotes: 7