I am in the processes of rebuilding a simple game program that I created to improve efficiency. I am running into trouble when I try to set an Icon to a JButton. The simpler version of the program runs perfectly with no issues in this area. I am using the same code to accomplish the same task here, but I am getting a lot of errors that I have not seen before. Could I get some help understanding the errors?
This is the path to the .jpg file: /Program/src/fire.jpg
This is the code I am using to add the icon to the button. The errors point to the line starting with new
, specifically the work new
when I space them out in Eclipse. The error does not lie in hand.[d]
, I have tested that thoroughly. Thanks for any help given.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {GraphicGameBoard.hand[d].setIcon(new
javax.swing.ImageIcon(getClass().getResource("/Program/fire.jpg")));}});
Stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at Program.Main$2.run(Main.java:168)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(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)