I have code that quietly runs in IDEA. But when you create a JAR file from it, it does not start.

java -jar jarname.jar

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at MainClass$1.run(MainClass.java:15) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(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$JavaSecurityAccessImpl.doIntersectionP rivilege(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) 

What I have in MainClass (15 line):

 frame.setIconImage(newImageIcon(MainClass.class.getResource("gui\\img\\reg.png")).getImage()); 
  • Instead of "gui\\img\\reg.png" try using the global path to the red.png file. - Kairat
  • The fact is that the reg.png file should be stored in the jar file, and if I specify the absolute path, then the jar file will be opened only on my computer. And I need to run everywhere. Sorry if I misunderstood you - Evertum
  • Will help? stackoverflow.com/a/1096491/6104996 ..... here's another version in Russian ru.stackoverflow.com/a/185542/191482 - Alexei Shimansky

0