0

When running this program I get this error code thrown back:

   java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at DebugMe.<init>(DebugMe.java:16)
    at DebugMe.main(DebugMe.java:31)

However no errors are being thrown within the compiler itself. The "debug.jpeg" image is within the same folder that the program is being run from as well.

import java.awt.*;
import javax.swing.*;

public class DebugMe extends JFrame
{
    private String message = "Congratulations, the program is working again.";
    Image debug = new ImageIcon(this.getClass().getResource("debug.jpeg")).getImage();
    int x; //Initialized x

    /**
     * Constructor for objects of class DebugMe
     */
    public DebugMe()
    {
        x = 0;
        setSize(500, 500);
        setVisible(true); //Lowercase t on true
    }

    public static void main(String[] args)
    {
        DebugMe myDebugMe = new DebugMe(); //capitalized me in Debugme
        int x;
    }

    public void paint(Graphics g)
    {
        super.paint(g);
        g.drawString("message", 100, 100);
        g.drawImage(debug, 100, 200, Color.BLUE, this);
    }
}
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
Para Lell
  • 7
  • 2
  • How are you running this? I tried this on command line and it works for me. There's probably an issue of where your running it from and relative to the resource. – Brandon Kearby Feb 14 '18 at 23:02
  • 1
    most probably `this.getClass().getResource("debug.jpeg")` is null – giorgiga Feb 14 '18 at 23:25

0 Answers0