Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default 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 '<<<----------'):

    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);
    I am kinda sick of screaming questionable things at my computer, so any help is appreciated.

    ps. ready to commence facedesking when I find out it's something really stupid.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    780
    Rep Power
    4

    Default 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!

  3. #3
    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    Default 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

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,928
    Rep Power
    16

    Default Re: Quick help needed

    Please go through the Forum Rules -- particularly the third paragraph.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. quick help
    By jwl in forum New To Java
    Replies: 3
    Last Post: 10-24-2012, 04:52 AM
  2. Should be a quick fix :)
    By Alienz in forum New To Java
    Replies: 5
    Last Post: 04-08-2011, 01:23 AM
  3. quick q&a
    By aizen92 in forum New To Java
    Replies: 2
    Last Post: 12-28-2010, 11:55 AM
  4. Quick help
    By Qwertypoiuy in forum New To Java
    Replies: 5
    Last Post: 01-06-2010, 10:49 PM
  5. Need help quick!
    By Manikyr in forum New To Java
    Replies: 11
    Last Post: 01-28-2009, 04:08 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
  •