I am trying to draw an image in my frame but I keep getting a NullPointerException. Here is what I have so far
package windows;
import BreezyGUI.*;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Title extends GBFrame{
static Graphics g ;
private BufferedImage bg;
public Title(){
bg = null;
try {
bg = ImageIO.read(new File("resources/images/TitleImage.png").toURI().toURL());
} catch (IOException e) {
e.printStackTrace();
}
g.drawImage(bg, 0, 0, null);
}
}
but it always ends up printing:
Exception in thread "main" java.lang.NullPointerException
at windows.Title.<init>(Title.java:22)
The image i need, TitleImage.png, is inside the folder "images" in the source folder "resources".
Any help for a beginner is appreciated.