tags:

views:

87

answers:

4

In my project I have 2 packages. images - contain images and notification - contain java files

In notification/main.java I get Image object from image using this code

Image image = Toolkit.getDefaultToolkit().getImage("/images/key-16x16.png");

and I can't get image.

How can I fix this bug.

A: 

haven't actually tried it out, but does it work if you get rid of the first slash?

piggles
+2  A: 

/ means an absolute path, save Java web-apps where / means relative to context. So, I would suggest to use relative URL, means get rid of that / in front, and then provide the right path.

In case, even then you can't solve it, try to create a file on the same path you are looking for image. This way you will know that where you are looking exactly and where you should look.

Adeel Ansari
+1  A: 

You could also try

Image image = new ImageIcon(path).getImage();
Bozho
A: 

I'm using Netbeans to develop Java desktop application and I have solved my problem.

//get image

Image image = new ImageIcon(this.getClass().getResource("/images/bell-icon16.png")).getImage();

"this" is a class extends JFrame

Chan Pye