I'm making it so that users can switch the theme of the icons for the JOptionPane (java defult, windows defult, and a custom one). the method works fine inside the class its declared in but when calling it outside of the class I'm getting this error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at GUI.setImageIcon(GUI.java:286) at Updater.checkForUpdates(Updater.java:28) at GUI.actionPerformed(GUI.java:172) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour ce) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(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 Sour ce) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour ce) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour ce) 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)
The method setImageIcon if defined in the class GUI. here it is:
public ImageIcon setImageIcon(String iconSet) { ImageIcon iconType = null; if (iconStyle.equals("Emotocons")) { if (iconSet.equals("inform")) { iconType = happyface; } if (iconSet.equals("error")) { iconType = angryface; } if (iconSet.equals("warning")) { iconType = anotherface; } } if (iconStyle.equals("java_defult")) { if (iconSet.equals("inform")) { iconType = javaInfo; } if (iconSet.equals("error")) { iconType = javaError; } if (iconSet.equals("warning")) { iconType = javaWarning; } } if (iconStyle.equals("windows_defult")) { if (iconSet.equals("inform")) { iconType = windowsInfo; } if (iconSet.equals("error")) { iconType = windowsError; } if (iconSet.equals("warning")) { iconType = windowsWarning; } } return iconType; }
Now when I call that outside of the class GUI is when i get there error. I'm calling it in the class Updater. here it is:
if (command.equalsIgnoreCase("update")) { JOptionPane.showMessageDialog(null, "There is a more recent version. " + "\nPlease download it on the website!", "Free RS Membership Updater", JOptionPane.WARNING_MESSAGE, g.setImageIcon("warning")); } else { JOptionPane.showMessageDialog(null, "You have the most recent version!", "Free RS Membership Updater", JOptionPane.INFORMATION_MESSAGE, g.setImageIcon("inform")); }
I did try this before and it said I didnt have the icons set visible but I rewrote the method since then and now I cant seem to get it to work.. please help!