Error inserting image icon in java - IllegalArgumentException

57 Views Asked by At

I'm developing a java project for a university exam. The project involves the creation of an application with the JDBC methodology. The project is almost finished, I was dedicating myself to the aesthetic part and here the problems begin :( . I'm trying to put an icon to the application with the following instructions:

public MainFrame() {
        try {
            setIconImage(ImageIO.read(getClass().getResourceAsStream("/resources/icon.png")));
        } catch (IOException e) {
            System.out.println("Icon Image could not be loaded");
        }

The console gives me this:

java.lang.IllegalArgumentException: input == null!
    at java.desktop/javax.imageio.ImageIO.read(ImageIO.java:1358)
    at Boundary.MainFrame.<init>(MainFrame.java:52)
    at Boundary.MainFrame$1.run(MainFrame.java:38)

How can I fix?

1

There are 1 best solutions below

1
Jens On

The resources folder does not exists inside the deliverable. You have to address it as it is in the root directory

setIconImage(ImageIO.read(getClass().getResourceAsStream("/icon.png")));