Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Setting image path correctly under a JAR file

pianomarpianomar Kuala LumpurMember Posts: 1

My very first question.
I created a simple slideshow desktop java program that works perfectly when I run it in the NetBeans environment.
However, after building it, and accessing the jar file using "java -jar", it shows an error.
MY QUESTION: Why is this error showing although the file heirarchy and the path specified are matching?

ERROR:

Method showing error:

public void showImage(int index) throws IOException{
        String[] imagesList = getImages();
        String imageName = imagesList[index];
ImageIcon icon= new  ImageIcon(ImageIO.read(getClass().getResourceAsStream("/Images/Images/"+imageName)));
        Image image = icon.getImage().getScaledInstance(ImageHolder.getWidth(),ImageHolder.getHeight(),index);
        ImageHolder.setIcon(new ImageIcon(image));
    }

**Heirarchy: **

What I have tried:

using an input stream like:
InputStream stream = getClass().getClassLoader().getResourceAsStream("Images/Images/"+imageName);
// ImageIcon icon= new ImageIcon(ImageIO.read(stream));

Removing the backslash before Images" in the path

putting the images folder in the same folder as the main class

Editing the manifest file manually

Not using the "File" Object as I realized it doesn't work in a jar file

Tagged:
Sign In or Register to comment.