So here is a part of my code thats throwing NullPointerException:
public class PuzzleGame extends GraphicsProgram implements KeyListener{
private ArrayList <PuzzleImage> list = new ArrayList <PuzzleImage>();
private PuzzleImage _11=null;
public static void main(String[] args) {
PuzzleGame game= new PuzzleGame();
game.setup(); //NullPointerException here
game.addKeyListener(game);
}
private void setup(){
BufferedImage img11 = null;
try {
img11 = ImageIO.read(new File("C://part11.png"));
} catch (IOException e) {
}
PuzzleImage _11=new PuzzleImage(img11,2,2,2,2); //NullPointerException here
list.add(_11);
}
}
And here is class PuzzleImage
public class PuzzleImage extends GImage {
public PuzzleImage(Image img, double x1, double y1, double realX, double realY) {
super(img, x1, y1); //NullPointerException here
x=x1;
y=y1;
}
private double x;
private double y;
private double realX;
private double realY;
}
So I made sure there is file named part11.png on C, so I am guessing path should be right. Now I honestly have no idea what is wrong with this code, however I am very new to java so it's likely there is just something I don't know or haven't seen. Maybe some of you guys could take a look and see if you can find anything? Thanks.
SOLVED: Turns out that out of like 12 images I am adding this one was only .jpg, and not .png. I guess it's getting late, I'm sorry to bother you guys.