File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Applets
Bookmark "Why am I getting NumberFormatException?" Watch "Why am I getting NumberFormatException?" New topic

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
Abhilash Vasudevan

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
Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
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
I agree. Here's the link:
subject: Why am I getting NumberFormatException?
jQuery in Action, 3rd edition