Saurabh Kumar
Saurabh Kumar

Reputation: 16651

NumberFormatException is throw on parsing a integer

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

Answers (7)

NamingException
NamingException

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

Mohd Mufiz
Mohd Mufiz

Reputation: 2236

try

Long.parseLong(1357679682162);

Upvotes: 1

THarms
THarms

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

Aditi
Aditi

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

Adrián
Adrián

Reputation: 6255

Java Integer Max value is 2147483647.

And you are trying to parse 1357679682162.

Upvotes: 0

partlov
partlov

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

Renjith
Renjith

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

Related Questions