File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Why am i getting NumberFormatException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why am i getting NumberFormatException" Watch "Why am i getting NumberFormatException" New topic

Why am i getting NumberFormatException

ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

I tried out the following :

int a=Integer.parseInt("11",2);
System.out.print(a); // output 3

int b=Integer.parseInt("015",8);
System.out.print(b);// output 13

int c=Integer.parseInt("0xf", 16); // NumberFormatException

I did not get why i am getting the exception.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

From the documentation:
Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value.

So you want

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
ashwin bhawsar
Ranch Hand

Joined: Mar 16, 2011
Posts: 62

Ohh, thanks.
I agree. Here's the link:
subject: Why am i getting NumberFormatException
It's not a secret anymore!