Howdy, Stranger!

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


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?


Method showing error:

public void showImage(int index) throws IOException{
        String[] imagesList = getImages();
        String imageName = imagesList[index];
ImageIcon icon= new  ImageIcon("/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(;

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

Sign In or Register to comment.