Hello everyone, i'm working on a little starting more advanced beginners project trying to create a basic 2d graphics engine. I have created a JFrame and a Canvas and added them both. The canvas is runnable and I have implemented a loop. When i want to getDrawGraphics from my buffer_strategy in the render method it gives me an error saying:
Exception in thread "Thread-2" java.lang.NullPointerException
at java.lang.Thread.run(Unknown Source)
I do not get this and have searched the internet for answers. I was not able to find them even on this forum. So I'm asking you to take a look at the code and tell me what might be wrong. Thank you :)
Link to source code at pastebin with linenumbers: http://pastebin.com/yJJP3XeC
Edited by: 957642 on 2012-sep-08 13:23
Edited by: 957642 on 2012-sep-08 13:25
From the stack trace the NPE originates from Main.java:126 . We don't know which is line 126.
Note - Unlikely to be the cause of your problem but Canvas is an AWT component and should not be used with Swing (JFrame). You should use a JPanel or JComponent and override the paintComponent() method.
I have now inserted the sourcecode and posted it on pastebin where linenumbers are visible
Three points :-
1) the posted code is not that associated with the stack trace you posted since nothing on line 126 could cause a NPE;
2) don't expect forum members to follow a link to code - post it here (using
3) given a stack trace that matches the published code you should easily be able to deduce what is wrong.