Can anyone help why am I getting error for my Java swing application that makes use of
ImageIcon(getClass().getResource()
to load images as shown below. Thanks in advance.
Code where error is shown:
jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/folder63.png")));
Error description:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at frame.foundation.initComponents(foundation.java:282)
at frame.foundation.<init>(foundation.java:21)
at frame.foundation$127.run(foundation.java:3453)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
PS: I have also added "images" folder as the source folder in my project
Folder Structure:
myprojectName
|
|___src
| |
| |___frame //(is my package)
| |
| |__foundation.java // main class
|
|__images
| |
| |__folder63.png
| |__d.jpg
| |__e.jpg
| |__f.jpg