Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Graphics object nullpointerException

800349Apr 20 2009 — edited Apr 20 2009
I'm making a game and it's suddenly broken. It was working fine, and it suddenly stopped. I know that programs don't just stop but I haven't modified any code from the bit which seems to be failing.
When running the program now, i receive the following error :
Uncaught exception java/lang/NullPointerException.
Now annoyingly it does not tell me where this is coming from so it makes life difficult to fix.
Manually sifting through the code due to the debugger being useless I've found what seems to be an error when creating the graphics object in the run method (threaded class) but I'm still confused
Graphics g = getGraphics();
If i place a simple System.out.println(); message before this, I am given the message before the error, and if I place it after I am given the message after the error, so I can only assume that the error is being caused here. However, when I use
System.out.println(g==null);
I am receiving the mess false. So g is not null so must be getting set.

The class extends the GameCanvas and implements Runnable. The Thread is being created in the constructor with
Thread t = new Thread(this);
            t.start();
Can anyone help.
Thanks

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 18 2009
Added on Apr 20 2009
1 comment
73 views