Click to See Complete Forum and Search --> : converting a string to integer error
sam_ccld
January 7th, 2003, 03:22 AM
I have this code
temp = token.nextToken().toString();
numero = Integer.parseInt(temp);
Is is giving me a numberFormatExeption error Knowing that temp is a string and numero is declared to be an interger
can anyone help
amolpg
January 7th, 2003, 03:30 AM
NumberFormatException indicates that string contains some non-numeric data, which converter is not able to convert.
Which string are you trying to convert?
Amol.
sam_ccld
January 7th, 2003, 03:47 AM
It is working now there was a space char before my string, i just saw it now, really it puzzeled me
Thank for your reply
Goodz13
January 7th, 2003, 09:19 AM
You might want to try and catch that exception.
int iNumber;
String sNumber = " 23";
try {
// trim the value and try to parse
iNumber = Integer.parseInt(sNumber.trim());
}catch(NumberFormatException nfe){
// it's not a number
}
[goodz13: edited:Sorry I should have looked the responce over before I posted]
sam_ccld
January 7th, 2003, 09:58 AM
Thanks Goodz13, you are right to be on the safe side i will be better off catching the exception
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.