Skip to content
Advertisement

“Exception in thread “AWT-EventQueue-0″ java.lang.NullPointerException” occurs while adding images using ImageIcon

Firstly i applied panel on whole background & then created a label to set an image here. JFrame picture

I saw that there’s so many questions & answers related to null pointer exception but no one worked for me. the ImageIcon is not being able to fetch the image. I even tried by creating a folder & gave the path but the error remains same. Netbeans: 12.5 jdk:8 Please help me.Thanks in advance.

JavaScript

The error shows,

JavaScript

The problem is in this line,

JavaScript

images on request to show the errors:

picture1 picture2 picture3 picture4

Advertisement

Answer

Given the project structure, the valid path string to the image will be:

JavaScript

Always use the / prefix to indicate a search from the root of the classpath.

Advertisement