Take the 2-minute tour ×

I'm trying to display two pictures on my JFrame, the way I found was to use icons and JLabels, this seems pretty straightforward and I'm not having problems with this. But when it comes to locating the image I can't get it to work. I'm on a linux machine thus the forwardslash style. I created a folder called pics in my project which is called 399assig1.

        ImageIcon icon1 = createImageIcon("/home/dsk03/ugrad/jeanbern/workspace/C291/workspace/399assig1/pics/fur-05.jpg","First");
    this.label1 = new JLabel("Picture 1", icon1, JLabel.CENTER);

    ImageIcon icon2 = createImageIcon("pics/fur.png","Second");
    this.label2 = new JLabel("Picture 2", icon2, JLabel.CENTER);

this is the error I get

Couldn't find file: /home/dsk03/ugrad/jeanbern/workspace/C291/workspace/399assig1/pics/fur-05.jpg
Couldn't find file: pics/fur.png
share|improve this question
Just a sidenote: in Java you can always use forward slashes as path delimiters - even on a MS Windows environment. –  Andreas_D Jan 25 '10 at 19:30

1 Answer 1

up vote 5 down vote accepted

if createImageIcon() is searching the CLASSPATH for the file, you'd need to add the root directory to the CLASSPATH. A better approach would be use a path that is relative to a directory that is already included in the CLASSPATH.

Like so:


then your call would be

ImageIcon icon1 = createImageIcon("399assig1/pics/fur-05.jpg", "MyIcon");
share|improve this answer

Your Answer


