This should work:
Main Topics
Browse All TopicsHey guys,
I was literally inches away from getting this working and I dont know where I've gone wrong...
I have made a simple java panel that is used for pounds and dollar conversion depending on rate. So I have a rate field, pound and dollar fields.
I want java to check for a field being empty, if so throw a JOptionPane alert. I got it to work at one point when the fields were default at 0, it was much easier to check a field for the presence of an integer at the time. What am I doing wrong?
Error: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatExce
at sun.misc.FloatingDecimal.r
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Wow, I can't believe it was that simple -.-, I will award you the points, but can you explain to me the importance of doing this method? Before I did the check for the field being blank, my floats were above the first if statement and it worked fine. Now that I'm checking the field for being empty I have to add them at the end. I just need to learn a little more before I give the points away otherwise I wont learn :)
Thanks for the help Ajay!
In the code you have, you parse the user input (by calling Float.parseFloat) first. In the case of bad input its going to throw an exception. The validation can be done alongwith you are parsing the input:
float pound, rate, result;
boolean valid = true;
try {
pound = Float.parseFloat(jTextFiel
} catch(ParseFailedException
// Incorrect input
valid = false;
JOptionPane.showConfirmDia
null, "Please enter a value for pounds", "alert", JOptionPane.OK_CANCEL_OPTI
}
if(valid) {
// parse rate
try {
rate = Float.parseFloat(jTextFiel
} catch(ParseFailedException
valid = false;
// Incorrect input
JOptionPane.showConfirmDia
null, "Please enter a value for rate", "alert", JOptionPane.OK_CANCEL_OPTI
}
}
if(valid) {
result = pound*rate;
jTextField3.setText(String
}
Business Accounts
Answer for Membership
by: Ajay-SinghPosted on 2008-06-14 at 04:37:25ID: 21784905
You should first validate the fields before convert it to float