Cristofer Fuentes
Cristofer Fuentes

Reputation: 441

Unknown Source when try to load image

I try to load an image in my desktop app but i don't know the route of the image

Error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.(Unknown Source) at ventanas.Success.(Success.java:30)

Code:

Image img = new ImageIcon(this.getClass().getResource("checked.png")).getImage();

My project tree:

enter image description here

I am try the next routes:

"checked.png"

"/checked.png"

"img/checked.png"

"/img/checked.png"

pd: img is a "Source Folder"

Upvotes: 0

Views: 450

Answers (1)

Lennart Deters
Lennart Deters

Reputation: 158

The img folder is not in the Build Path.

The little package symbol in the folder icon indicates that. Press Right Mouse on the img Folder, select Build Path and click Use as Source Folder

If for some reason it still is not in the Build path click Configure Build Path... and add it manually.

Upvotes: 2

Related Questions