我正在尝试在JFrame
我正在编程的小型游戏上显示背景图像。该图像是 .jpg,我不断收到以下错误:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:205)
at web.game.Base.<init>(Base.java:45)
at web.game.Base.main(Base.java:61)
我的代码是:
Image myimage;
public Base() {
ImageIcon ii = new ImageIcon(this.getClass().getResource("myimage.jpg"));
myimage = ii.getImage();
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(myimage, 10, 10, null);