Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

validating for an empty JOptionPane dialog

807600Dec 3 2007 — edited Dec 12 2007
Hi there,

I am attempting to validate a JOptionPane dialog for an empty input or if the cancel button is pressed by using the following line of code below:
String response;
response = JOptionPane.showInputDialog(null, "Please enter something");

if(response == null)
{
    JOptionPane.showMessageDialog(null, "Error Message");
}
else
{
    JOptionPane.showMessageDialog(null, "Thank you");
}
However it does not seem to be functioning like it should, I click the Ok button it just exits the application and gives a java generated error message and the same happens when I click the cancel button.

I would appreciate it if someone could explain why that is so..

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 9 2008
Added on Dec 3 2007
1 comment
467 views