Results 1 to 10 of 13
so here is my code:
Code:
public static void main(String args[])
{
String theinfo;
addmfr_resell mfr = new addmfr_resell();
mfr.addMfrSell ("Hasbro");
mfr.addMfrSell ("Dewall Power Tools");
mfr.addMfrSell ("Nintendo");
mfr.addMfrSell("Apple");
mfr.addMfrSell ("Ajax");
...
- 12-05-2008 #1
Java NullPointerException help
so here is my code:
I keep getting a NullPointerException at "showinfo.setText (theinfo);"Code:public static void main(String args[]) { String theinfo; addmfr_resell mfr = new addmfr_resell(); mfr.addMfrSell ("Hasbro"); mfr.addMfrSell ("Dewall Power Tools"); mfr.addMfrSell ("Nintendo"); mfr.addMfrSell("Apple"); mfr.addMfrSell ("Ajax"); mfr.addMfrSell ("Acme"); mfr.addMfrSell ("Napa"); mfr.addMfrSell ("Eureka"); mfr.addMfrSell ("Hoover"); theinfo = mfr.toString(); showinfo.setText (theinfo); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new retailGUI().setVisible(true); } }); }
I am at a complete lost as to how to fix this... I swear that everything is declared... whats going on?"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442
- 12-05-2008 #2
is showinfo declared? cause if not, or if it's null, it will throw a NullPointerException
- 12-05-2008 #3
I'm pretty sure it is declared.... showinfo is a JTextArea, what whould i have to do to declare it? I build the GUI before i start that snippit of code...
"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442
- 12-05-2008 #4
did you construct it ever? if it was a data member, and was never constructed, it will just be a null object, and you can't set the text of a null object.
- 12-05-2008 #5
i thought i did... how could i tell if i constructed it?
"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442
- 12-05-2008 #6
JTextArea showinfo = new JTextArea();
this is the default constructur, with x and y set to zero, and the string text set to null. you can check out the other constructors on the API under "Constructor Summary":
JTextArea (Java Platform SE 6)
- 12-05-2008 #7
showinfo = new javax.swing.JTextArea();
Isn't that the same thing?"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442
- 12-05-2008 #8
Have you tried stepping through it using a debugger? Put a breakpoint on the line where you're attempting to set the value and check all the existing variables to see which one is null.
Registered Linux user #270181
TechieMoe's Tech Rants
- 12-05-2008 #9
I want to make sure i'm understanding this...
I get the nullpointerexception because my object showinfo isn't constructed right? but does it not get constructed when i tell it to show up for my GUI?"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442
- 12-05-2008 #10
I did that, and everything went as it was supposed to, but it still gave me my null exception...
ok, so correct me if i'm wrong, but the setText() allows me to set the text of an object right? So I have my JTextArea and i want to set the text in there to strings in my array list right?"Do or do not...there is no try" -Yoda
History is a set of lies agreed upon by the winners.
Linux is user friendly, not idiot friendly.
Linux User 437442


Reply With Quote
