Im trying to draw an image in java. It was working before I created a separate class just to store the images. But now I get Null pointer exception.
Main class:
Image image;
Images images; // class object
public void paint(Graphics G){
image = images.GETImage();
G.drawImage(image, x, y, 20,20,null);
}
protected void paintComponent(Graphics G){
paint(G);
}
Image Class to store images:
public Image GETImage(){
int direction = pacman.getDirection();
int newDirection = pacman.getDirection();
int x = pacman.getX();
int y = pacman.getY();
if(direction == Constant.UP){
ImageIcon i = new ImageIcon("src\\images\\pacman up.png");
image = i.getImage();
}
return image;
}