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

    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(
    at java.awt.Container.add(
    at GUI.<init>(
    at GUI.main(

    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.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); <<<-----------
    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
    Rep Power

    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
    Rep Power

    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.


  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Quick help needed

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

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

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