I need to create an array of images. when I try to do the getGraphics
method of the Graphics class to access the Image I created in the array index it throws the java.lang.NullPointerException error even though a few lines above I created the image in that index
I tried changing the index and changing the condition of the foor loop, but it still enters the loop only once and says that the array in index 0 is null.
private Image[] frames = new Image[100];
for (int index = 0; index < frames.length; index++){
if (frames[index] == null)
{
frames[index] = this.createImage(SCREEN_WIDTH, SCREEN_HEIGHT);
}
Graphics graphic = frames[index].getGraphics();
I expect the array to be full of images at the end, in order to paint them and finish the job.