Forum Stats

  • 3,873,311 Users
  • 2,266,534 Discussions


Graphics object nullpointerException

800349 Member Posts: 130
edited Apr 20, 2009 6:24PM in Java ME SDK
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
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);
Can anyone help.


This discussion has been closed.