Results 1 to 15 of 15
Thread: [SOLVED] Trouble a method
- 03-02-2009, 07:34 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
[SOLVED] Trouble a method
This is my first time for entering any information. Here goes...
Here's my code:
Here's what i have.
public static void main (String [] args )
{
Pixel currPixel = null;
Pixel oldPixel = null;
Pixel newPixel = null;
Picture p = null;
Picture oldBackground = null;
Picture newBackground = null;
Picture newBg = null;
Picture oldBg = null;
String getMediaPath;
Scanner keyboard = null;
keyboard = new Scanner(System.in);
String jpgFileName = null;
double threshold = 0;//-1.0;
String runAgain = "Y";
double userPromt = 50.0;
Picture lowerLimit = null;
Picture upperLimit = null;
This is part of my main method. My error occurs at line 210.
code in main method
208 newBg.hide();
209 // now the swapBackground method will run
210 threshold = validateDouble ("Enter a background and threshold double", 0.0, 200.0);
211 p.swapBackground(oldBackground, newBackground, threshold);
212 newBg.repaint();
213 JOptionPane.showMessageDialog( null, "This is your updated picture");
214 newBg.hide();
error message:
java.lang.NullPointerException
at Picture.swapBackground(Picture.java:1653)
at PA5BeckleyMain2ndTry.main(PA5BeckleyMain2ndTry.jav a:211)
Can you help?
- 03-02-2009, 07:43 PM #2
Member
- Join Date
- Apr 2007
- Location
- Indiana
- Posts
- 83
- Rep Power
- 0
Can you post your validateDouble() method? Does it return the primitve double?
- 03-02-2009, 08:13 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
pegitha,
hope this helps
//----------------------------------------------------------------------------------------------
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);
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()
What am I supposed to enter in the input box
threshold = validateDouble ("Enter a background and threshold double", 0.0, 200.0);
when this pops up?
Thanks,
Robocop
- 03-03-2009, 06:00 PM #4
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
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)
- 03-03-2009, 08:58 PM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
showInputDialog can also return null, so you should perhaps test for that as well. Maybe that's the source of the NPE - it's hard to say as you didn't say which line 289 is.Java Code:if (doubleString.length() == 0) validNumeric = false; if (doubleString.length() > 0 ) // etc
(This seems to be a double post - it might make things a little clearer if you direct people in the other thread to reply here where you have more code.)
- 03-03-2009, 08:59 PM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
What do you mean? It's your code: surely you know what you intended to be entered into the dialog box...What am I supposed to enter in the input box
threshold = validateDouble ("Enter a background and threshold double", 0.0, 200.0);
when this pops up?
- 03-03-2009, 10:00 PM #7
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
here is the rest of the data. I want to enter 50.0 in the dialog box. I'm new at this so please bear w/ me
//----------------------------------------------------------------------------------------------
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()
-
a double or cross post of the same question?
- 03-03-2009, 10:31 PM #9
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
I am trying to enter a double, 50.0, if this is what your asking
- 03-03-2009, 10:47 PM #10
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
its the same question
- 03-03-2009, 10:54 PM #11
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
doubleString is not initialized. fix that.
- 03-03-2009, 11:05 PM #12
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
is this where I initialize it? and have i done it correctly?
public static void main (String [] args )
{
Boolean validNumeric;
double doubleValue = -1.0;
String doubleString;
String setOfValidDigits = "0123456789";
Pixel colorDistance = null;
Pixel currPixel = null;
Pixel oldPixel = null;
Pixel newPixel = null;
Picture p = null;
Picture oldBackground = null;
Picture newBackground = null;
Picture newBg = null;
Picture oldBg = null;
Picture mark = null;
String getMediaPath;
//Scanner keyboard = null;
//keyboard = new Scanner(System.in);
String fileName = null;
double threshold = -1.0;
String runAgain = "Y";
double userPromt = 50.0;
Picture lowerLimit = null;
Picture upperLimit = null;
String validateDouble = "threshold";
-
I answered your question in the other thread. Please don't create two threads with the same question. This frustrates us to no end. Also, you've been here long enough to start using code tags. Please do so.
- 03-03-2009, 11:21 PM #14
Member
- Join Date
- Feb 2009
- Posts
- 14
- Rep Power
- 0
I apologize for creating two threads. like i said i'm new @ this and don't understand all the terms. As far as being here long enough and using code tags, what is a code tag???
-
My standard post on code tags:
When posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:
Java Code:[code] // your code goes here // notice how the top and bottom tags are different [/code]
Similar Threads
-
[SOLVED] Method trouble >:0!
By PureAwesomeness in forum New To JavaReplies: 10Last Post: 02-20-2009, 06:18 AM -
Trouble with method
By BlueJ2008 in forum New To JavaReplies: 2Last Post: 10-19-2008, 09:05 PM -
Trouble will calling a method
By jonsamwell in forum New To JavaReplies: 9Last Post: 08-22-2008, 10:16 PM -
having some trouble
By Unknown1369 in forum New To JavaReplies: 13Last Post: 07-21-2008, 11:52 PM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks