0

Before writing this question, I searched on the internet and tried most of the ways but I still can't find to solve my problem. My program works well on the eclipse but when I want to make an executable jar file and try to run it from the command window, it throws an IllegalArgumentException. My package is as follows:

Package

And my code:

public JLabel getLabel() {
    JLabel label = null;
    try {
        String address = "assets/" + pieceName + ".png";
        InputStream is = this.getClass().getClassLoader().getResourceAsStream(address);
        BufferedImage image = ImageIO.read(is);
        ImageIcon imageIcon = new ImageIcon(image);
        label = new JLabel(imageIcon);
    } catch (IOException e) {
        e.printStackTrace();
    } 
    return label;
}

So basically, my 'is' value is getting null even though the address is working for all of the possibilities on the eclipse. I tried putting '/' before the assets but at that time, program is not even compiling in the eclipse. I also checked the jar file with winrar and here is the screenshot:

Jar File

And here is the command window's screenshot:
Command Window

Thanks for reading, have a nice day.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

0 Answers0