Results 1 to 2 of 2
  1. #1
    jason99 is offline Member
    Join Date
    Jul 2009
    Rep Power

    Default Problem JOptionPane try catch

    import javax.swing.JOptionPane;

    public class trycatch
    public static void main(String args[])
    boolean loop=false;

    String strinput=JOptionPane.showInputDialog(null,"Enter a integer");
    int input=Integer.parseInt(strinput);

    catch(NumberFormatException ex)
    OptionPane.showMessageDialog(null,"Invalid value entered");


    can some one help me solve this , the problem is once the exception is catch then the CANCEL & CLOSED OPTION cant close the JOptionPane,thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    1) You'll want to set your loop variable to false at the beginning of the try block. Otherwise if you enter bad input once, you will loop forever, even if good input is given later.
    2) You'll want to check if the String returned from the showInputDialog method is null or not. Play with this and you'll figure it out.

    Best of luck.

Similar Threads

  1. [SOLVED] JOptionPane.ShowConfirmDialog() problem
    By jon80 in forum New To Java
    Replies: 15
    Last Post: 06-03-2009, 02:37 AM
  2. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 10:54 AM
  3. JOptionPane problem
    By MomenT in forum New To Java
    Replies: 22
    Last Post: 10-02-2008, 05:56 PM
  4. [SOLVED] On Exit JoptionPane problem
    By Mir in forum New To Java
    Replies: 24
    Last Post: 07-15-2008, 07:39 AM
  5. Problem with JOptionPane.showInputDialog()
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts