|
-
January 7th, 2003, 04:22 AM
#1
converting a string to integer error
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
-
January 7th, 2003, 04:30 AM
#2
NumberFormatException indicates that string contains some non-numeric data, which converter is not able to convert.
Which string are you trying to convert?
Amol.
-
January 7th, 2003, 04:47 AM
#3
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
-
January 7th, 2003, 10:19 AM
#4
You might want to try and catch that exception.
Code:
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]
Last edited by Goodz13; January 7th, 2003 at 02:20 PM.
-
January 7th, 2003, 10:58 AM
#5
Thanks Goodz13, you are right to be on the safe side i will be better off catching the exception
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|