Results 1 to 4 of 4
Thread: Quick help needed
- 10-24-2012, 05:37 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Quick help needed
I am trying to create a game of 'Pig' using a precoded die and gui class (school project), and am getting the following exception:
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1045)
at java.awt.Container.add(Container.java:365)
at GUI.<init>(GUI.java:53)
at GUI.main(GUI.java:37)
It is flagging these lines of code (denoted with '<<<----------'):
I am kinda sick of screaming questionable things at my computer, so any help is appreciated.Java Code:public static void main(String args[]){ // the traditional five lines of code from the book are // provided in the GUI constructor new GUI(); } public GUI(){ <<<--------- // create the game object as well as the GUI Frame ButtonListener buttonListener= new ButtonListener(); game = new Pig(); myGUI = new JFrame(); myGUI.setSize(400,400); myGUI.setTitle("Taylor's Game of Pig"); // place the die in the middle of the screen JPanel panel = new JPanel(); d1 = game.getDie(1); d2 = game.getDie(2); panel.add(d1); <<<----------- panel.add(d2); myGUI.add(panel);
ps. ready to commence facedesking when I find out it's something really stupid.
- 10-24-2012, 05:49 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: Quick help needed
d1 is null? So it looks like that getDie(..) returns null. Why? We don`t know, take a look at your Pig class!
- 10-25-2012, 06:30 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 4
- Rep Power
- 0
Re: Quick help needed
Well, thanks for the help, but I think I found the problem:
I misread what was going to what, and it turns out my Pig class needs a complete rewrite.
In other words, PICNIC error: Problem In Chair, Not In Computer.
Cheers!
AlternateLives
- 10-25-2012, 06:38 PM #4
Re: Quick help needed
Please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
quick help
By jwl in forum New To JavaReplies: 3Last Post: 10-24-2012, 04:52 AM -
Should be a quick fix :)
By Alienz in forum New To JavaReplies: 5Last Post: 04-08-2011, 01:23 AM -
quick q&a
By aizen92 in forum New To JavaReplies: 2Last Post: 12-28-2010, 11:55 AM -
Quick help
By Qwertypoiuy in forum New To JavaReplies: 5Last Post: 01-06-2010, 10:49 PM -
Need help quick!
By Manikyr in forum New To JavaReplies: 11Last Post: 01-28-2009, 04:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks