Results 1 to 4 of 4
  1. #1
    robocop is offline Member
    Join Date
    Feb 2009
    Posts
    14
    Rep Power
    0

    Unhappy [SOLVED] Passing parameters

    What is wrong with this code? Here's my code, and below it is the error code that pops up in the interactions pane while running the program.

    Still need help with the following code:


    JOptionPane.showMessageDialog( null, "You have chosen T");

    // the user will pick a picture
    fileName = FileChooser.getMediaPath("twoKidsWall.jpg");
    p = new Picture(fileName);
    p.show();
    JOptionPane.showMessageDialog( null, "This is the 1st picture that you picked");
    p.hide();
    // the user now picks the 2nd picture
    fileName = FileChooser.getMediaPath("wall2.jpg");
    oldBackground = new Picture(fileName);
    oldBackground.show();
    JOptionPane.showMessageDialog( null, "This is the 2nd picture that you picked");
    oldBackground.hide();
    // the user will pick a third picture
    fileName = FileChooser.getMediaPath("bridge.jpg");
    newBackground = new Picture(fileName);
    newBackground.show();
    JOptionPane.showMessageDialog( null, "This is the 3rd picture that you have chosen");
    newBackground.hide();

    // now the swapBackground method will run
    threshold = validateDouble ("Enter a background and threshold double", 0.0, 200.0);
    //p.swapBackground(oldBackground, newBackground, threshold);
    p.swapBackground(oldBg, newBg, 50.0);//threshold);

    Here is my error message:

    java.lang.NullPointerException
    at PA5BeckleyMain2ndTry.validateDouble(PA5BeckleyMain 2ndTry.java:289)
    at PA5BeckleyMain2ndTry.main(PA5BeckleyMain2ndTry.jav a:217)

    please help!::eek:

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Please post the ValidateDouble method and highlight line 289 (should be somewhere in that method)
    Last edited by Supamagier; 03-03-2009 at 07:34 PM.
    I die a little on the inside...
    Every time I get shot.

  3. #3
    robocop is offline Member
    Join Date
    Feb 2009
    Posts
    14
    Rep Power
    0

    Default

    here is the method, I am trying to enter 50.0

    //----------------------------------------------------------------------------------------------
    public static double validateDouble(String userPrompt, double lowerLimit, double upperLimit)
    //----------------------------------------------------------------------------------------------
    {
    Boolean validNumeric;
    double doubleValue = -1.0;
    String doubleString;
    String setOfValidDigits = "0123456789";

    do
    {
    validNumeric = true;
    doubleString = JOptionPane.showInputDialog(userPrompt);
    289 if (doubleString.length() == 0)
    validNumeric = false;
    if (doubleString.length() > 0 )
    for (int i = 0; i < doubleString.length(); i++)
    if (setOfValidDigits.indexOf(doubleString.charAt ( i ) ) < 0)
    validNumeric = false;
    if (validNumeric)
    doubleValue = Double.parseDouble(doubleString);
    }
    while (doubleValue < lowerLimit || doubleValue > upperLimit || !validNumeric);

    return doubleValue;

    }//End method double validateDouble()

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So, what does that tell you that the JOptionPane returns if the user presses cancel? Answer: A null!

    To solve this, first check if the String is null before doing anything else.

Similar Threads

  1. Replies: 1
    Last Post: 01-16-2009, 11:14 AM
  2. passing parameters to paint mtd
    By themburu in forum Java Applets
    Replies: 3
    Last Post: 07-14-2008, 09:15 PM
  3. passing parameters between two applets
    By veena1612 in forum Java Applets
    Replies: 1
    Last Post: 05-27-2008, 10:29 AM
  4. [SOLVED] Passing parameters in Eclipse
    By DonCash in forum Eclipse
    Replies: 2
    Last Post: 04-08-2008, 05:46 PM
  5. JNI - passing and returning parameters by value
    By java_to_c in forum New To Java
    Replies: 0
    Last Post: 01-31-2008, 09:49 PM

Posting Permissions

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