Problem in Game Engine

I Have this problem in my game engine where I am trying to create a double buffering image and it keeps saying null. I have tryed to debug but still cant get this to work. I only have today to get it to work so I would love it if you fix it thanks Toby.

Code here https://www.dropbox.com/s/25wm2wcaz77awkg/Eclispe%20Workspace.zip

Ha anybody got a idea yet I have been working on this for hours and still cant find the bug. It needs to done by 1

Can you post the stack trace, would make it a lot easier to diagnose.

I know what you mean, an easy solution is to check if the bufferedimage == null in the render method and if that is true, bufferedimage= new buf…
else
bufferedimage.getGraphics(); etc.

Thats what I do i check the buferedImage 2 first time create it second time print the err message.

Why are you using the variable type Image for your “doubleBufferImage”

Why not used BufferedImage for your bufferimage?

The graphics object you are trying to retrieve from g = this.getGraphics(); is returning null. Although you check it before you render, you get a NPE when you try to dispose of it.

I think you have done some things backwards with regards to JFrame and JPanel.

Here is some source code, that is pretty much identical to what you are doing, with some refactored/renamed elements
Specifically with GamePanel.java and Main.java, similiar to your Core_Main and Core_Window
http://www.thejavahub.net/thejavahub/index.php?topic=266.0
It should show you whats gone wrong.
The issue isn’t with doubleBufferImage = createImage or the null gameRender() part
It lies in a deeper and broader issue with how you have your entire program setup.

Specifically you are creating a JFrame inside your JPanel, when it should be the other way around. The public static void main should be in your JFrame, not in your JPanel


You can follow along as they write most of what you have there, pay special attention to things that are different.
Ignore the areas outside of the JFrame and JPanel class, specifically with rendering and basic setup

I got it working with the code, however it requires a lot of various small changes in Core_Main and Core_Window that’d just be a pain to most here, but those 2 links should get you going without too much difficulty.

:expressionless:

Well it is a game engine for home use and I have looked at the javahub but I would then need to change all my code and add more classes but I dont have time. So I would rather do the small changes as a temporary solutions then come back to the problem.

I have had this error before it is generally annoying what I would do is check each variable being put into the functions so System.out.println(g); is an example. if any of them are null then you can tell us the issue.