plz can anyone help me(urgently required) how to get an integer from a text field
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   kumar_john
Posted On:   Wednesday, June 27, 2007 10:52 AM

How can i get an integer from a textfield



i done it following maner but it didn't work



int x = Integer.parseInt(t1.getText());



it shows an error like this:


java.lang.NumberFormatException: For input string: " 235454"



plz plz help me what i will do ???

Re: plz can anyone help me(urgently required) how to get an integer from a text field

Posted By:   Anonymous  
Posted On:   Friday, June 29, 2007 10:41 AM

i think the problem is because you have a space at the

start of the string. try



int x = Integer.parseInt(t1.getText().trim() );

Re: plz can anyone help me(urgently required) how to get an integer from a text field

Posted By:   ramanujam_ragavan  
Posted On:   Wednesday, June 27, 2007 12:05 PM

Is there a whitespace before the 2? watch for that... Also, in order to be able to handle any such condition, do two things..



1. Do a validation before calling the Integer.parseInt() method

2. Just as a what-if case, surround the parseInt with a try catch and handle the exception...



Otherwise there is no reason I see why the code should fail...
About | Sitemap | Contact