Results 1 to 5 of 5
  1. #1
    peter_62au is offline Member
    Join Date
    Dec 2013
    Posts
    18
    Rep Power
    0

    Default JOptionPane.showInputDialog not appearing properly.

    I've written a program that requires a number of variables to be input by the user before making calculations using these and other variables from file. The variables are input using JOptionPane.showInputDialog. The variables are Strings, doubles and integers.
    My problem is that sometimes the input window does not appear properly, just a blank window, no input box or buttons just the cross in the right corner. Depending on when it happens sometimes when I click the cross the error exception catches the null value and loops, the window appears properly and the program continues as if nothing bad happened. Other times it just crashes.
    i don't think it is a code problem because it happens randomly in different places for different input data and when I run it again using exactly the same data it will run through correctly with no problems. I hope someone knows why this occurs as it is driving me nuts.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: JOptionPane.showInputDialog not appearing properly.

    There's no way helping you without seeing the code or an SSCCE
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    peter_62au is offline Member
    Join Date
    Dec 2013
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane.showInputDialog not appearing properly.

    here are 2 examples of my code but it doesn't occur exclusively in these spots it happens randomly or not at all.

    Without error checking

    Java Code:
                intDistLstSt[i] = Integer.parseInt(JOptionPane.showInputDialog(strHrsNames[i] + "\n: Distance last Race",intDistance[i]));
    and in another Method with error checking

    Java Code:
                    while ( blError) {
                        strTemp = JOptionPane.showInputDialog(strHrsNames[Index] + "\n: Distance last Race");
                        try {
                            intDistLstSt[Index] = Integer.parseInt(strTemp);
                            blError = false;
                        } catch(NumberFormatException e){
                            blError = true;
                        }
                        if ((intDistLstSt[Index] < 1000)|| (intDistLstSt[Index] >= 3600)){
                            JOptionPane.showMessageDialog(null, "Invalid Last Distance","ERROR",JOptionPane.ERROR_MESSAGE);
                            blError = true;
                        }                
                    }
    Sometimes the error occurs, sometimes not, and when it does I can rerun the program using exactly the same data and it runs without a problem.

  4. #4
    peter_62au is offline Member
    Join Date
    Dec 2013
    Posts
    18
    Rep Power
    0

    Default Re: JOptionPane.showInputDialog not appearing properly.

    Still none the wiser why I'm getting blank windows but I have at least worked out how to stop the program crashing everytime it happens added a second catch
    Java Code:
                          catch(NullPointerException e){

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,917
    Rep Power
    5

    Default Re: JOptionPane.showInputDialog not appearing properly.

    That's making the problem go away and that is the worst thing you can do at this point; remove that catch ASAP and return to working on how to solve the problem.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Help with JOptionPane.showInputDialog
    By Rahim2312 in forum New To Java
    Replies: 13
    Last Post: 05-01-2012, 02:10 AM
  2. JOptionPane.showInputDialog with only 1 correct answer
    By Gladiat0r in forum New To Java
    Replies: 1
    Last Post: 03-18-2012, 09:42 PM
  3. Problem in showInputDialog
    By mghaheri in forum New To Java
    Replies: 1
    Last Post: 03-05-2009, 11:29 PM
  4. JOptionPane.showInputDialog
    By mayhewj7 in forum New To Java
    Replies: 5
    Last Post: 02-25-2009, 06:04 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
  •