This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Why am I getting NumberFormatException?" Watch "Why am I getting NumberFormatException?" New topic
Author

Why am I getting NumberFormatException?

Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
Can anyone tell me why I'm getting a NumberFormatException, coz for the life of me I can't see whats wrong with it.
It's basically an applet that allows you to enter 2 numbers which when you click on 1 of 4 radio buttons( +, -, *, / ) and then click calculate, displays the answer in a JTextField. I've used the method getText() to retrieve the inputted strings, then converted these to ints, did the calculation, then converted them back to a String in order to display in the result JTextField.(Is it possible to leave the result as an int to display in result field?)

Any help would really be appreciated


Rob Petterson
SCJP
Abhilash Vasudevan
Greenhorn

Joined: Mar 31, 2003
Posts: 19
It seems you are parsing the textfields for the val1 and val2 in the init(). But at initialising time you will not have anything in there.
This has to be done once you have typed in some number in there and clicked the calculate button.
So include the val1,val2 assigning statements inside your action performed method and then it should work
Regards
Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
Abhilash,
Iv'e done as you said and moved the assignments to here:

So, I now get the GUI displaying propery. I can enter 2 numbers into the textfields and click on a radio button such as'+' to add the 2 numbers together. I then click the 'calculate' button but nothing appears in the result textfield.
Is there something wrong in the if statements to do with setText()???
Nicholas Turner
Ranch Hand

Joined: May 24, 2003
Posts: 126
do a repaint()
If your curious about the values do debugging like so
System.err.println("val1 = " + val1);
then open the Java console and check the values out
 
 
subject: Why am I getting NumberFormatException?
 
Similar Threads
Alignment Issue
Multiple Windows in Applets
JTextArea scroll bar
JTextField with JOptionPane - showMessageDialog (please help)
How do I get my button to work?