Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: NullPointerException when canceling JOptionPane.showInputDialog

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question NullPointerException when canceling JOptionPane.showInputDialog

    Hello

    I am a beginner in java, so I guess my question might sound trivial to some.
    I am writing some code to execute the setup of some computations. The computation needs the definition of 'continuum'.
    First, I am collecting the continuum. If there are no continuum define, I am asking the name to the the user.
    Everything is working fine, except that if I choose the "cancel" button, I am getting a null pointer exception while exiting.
    So my question is: how to properly cancel and exit?
    Thanks for any help

    Integer contMgr =
    	simulation_0.getContinuumManager().getChildrenCount();
     
    	if (contMgr == 0)
                {
                continuum= JOptionPane.showInputDialog("Enter the name of the Continuum", "" );
                                //-----------------------------------------------------//
                                //	If the user use the 'Cancel' option, exit of the Macro	//
                                //----------------------------------------------------//
    				if (continuum == null)
                                        {
                                        JOptionPane.showMessageDialog(null,
                                                                    "Canceling the Computation Setup",
                                                                    "Canceling",JOptionPane.WARNING_MESSAGE);
                                        return;
                                        }
                }
          else blalbalbala


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,306
    My Mood
    Mellow
    Thanks
    194
    Thanked 669 Times in 656 Posts

    Default Re: NullPointerException when canceling JOptionPane.showInputDialog

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Review the code that executes after the 'Cancel' is selected. Something null is being processed by the exiting code, so check for the null and create a different path that avoids that result.

Similar Threads

  1. need help in JOptionPane
    By Zuckerberg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 28th, 2014, 06:08 AM
  2. Change to JOptionPane
    By Liuric in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2010, 12:07 AM
  3. JOptionPane using If and Else
    By Liuric in forum Member Introductions
    Replies: 7
    Last Post: October 1st, 2010, 12:05 AM
  4. NullPointerException when canceling JOptionPane.showInputDialog
    By Shaddam in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 2nd, 2010, 02:08 AM
  5. showInputDialog method
    By chronoz13 in forum AWT / Java Swing
    Replies: 2
    Last Post: November 22nd, 2009, 04:47 PM