0

Exception in thread "main" java.lang.NullPointerException at java.desktop/javax.swing.ImageIcon.(ImageIcon.java:217) at mystia1123.Receipt.(Receipt.java:17) at mystia1123.Receipt.main(Receipt.java:35)

    package mystia1123;

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

    public class Receipt extends JFrame {

    private JFrame frame;
    private ImageIcon image;
    private JLabel jLabel;

    public Receipt(){

    image=new ImageIcon(getClass().getResource("1.png"));
    jLabel = new JLabel(image);
    jLabel.setSize(650,450);




    frame=new JFrame("Receipt");
    frame.add(jLabel);
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    frame.setLocationRelativeTo(null);
    frame.pack();

    }

    public static void main(String[] args) {
    new Receipt();
    }
    }
Elbert Jn
  • 195
  • 7
  • Because your image 1.png is not accessible. It must be in the classpath, and in the package mystia1123. – Maurice Perry Jun 16 '20 at 09:06
  • File "1.png" can't be found, you have similar question here: https://stackoverflow.com/questions/5769351/java-getclass-getresourcefile-leads-to-nullpointerexception – tieburach Jun 16 '20 at 09:07

0 Answers0