-2

I get a NullPointerException on the following statement when I run my code in Eclipse 3.6.1:

private ImageIcon initialicon = new ImageIcon(gbarsStatusPlusTest.class.getResource("/images/waitingLight.GIF"));

I've read through posts with similar questions and tried the answers with no luck, including:

  • Using the absolute path
  • Using various relative paths
  • Putting the gif in various folders (src, bin, lib, etc)
  • Creating waitingLight.gif->waitingLight.GIF link

My current project path to the image is LosOMeter->src->images->waitingLight.GIF.

Any ideas?

Stack trace:

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
 at javax.swing.ImaqeIcon.<init>ImaqeIcon.java:205)
 at geolosmeter.gbarsStatusPlusTest.<init>(gbarsStatusPlusTest.java:85)
 at geolosmeter.gbarsStatusPlusTest$5.run(gbarsStatusPlusTest.java:2848)
 at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
 at java.awt.EventQueue.dispatchEventlmp(EventQueue.java:745)
 at java.awt.EventQueue.access$300(EventQueue.java:103)
 at java.awt.EventQueue$3.run(EventQueue.java:706)
 at java.awt.EventQueue$3.run(EventQueue.java:704)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.security.ProtectionDomain$JavaSecurityAccesslmpl.dolntersectionPrivilegeProtectionDomain.java:76)
 at java.awt.EventQueue.dispatchEvent(EventQueue.java:715)
 at java.awt.EventDispatchThread.pumpOneEventForFilter(EventDispatchThread.java:18)
 at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:133)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:22)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:118)
 at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:110)
 at java.awt.run(EventDispatchThread.java:91)
Doug Fulford
  • 49
  • 11
  • 1
    Try removing the / at the beginning of your path. Does that help? Where is your image relatively to your gbarsStatusPlusTest class? Is it in the same JAR file? – Janos Vinceller Oct 12 '20 at 19:27
  • This issue is not related to eclipse, but with your system path. You should give absolute path of your image file. – Simmant Oct 12 '20 at 20:31
  • I tried both removing the / at the beginning of the path and using the absolute path. Neither worked. – Doug Fulford Oct 12 '20 at 22:51
  • 1
    *"Putting the gif in various folders (src, bin, lib, etc)"* Since you're attempting to load it as a class path resource, it belongs under your project's resources directory. See https://stackoverflow.com/questions/27934796/how-do-i-add-a-resources-folder-to-my-java-project-in-eclipse – dnault Oct 12 '20 at 23:26
  • You don't have to put your gif file into random locations, instead its containing directory `images` should be on the classpath. If you create a `jar` file, simply add `images` into the jar. If you create a `war` file, put `images` under `WEB-INF/classes` inside the `war`. – Lorinczy Zsigmond Oct 14 '20 at 00:00

1 Answers1

0

Thank you dnault. stackoverflow.com/questions/27934796/… is the answer. I think my issue was that I was porting from eclipse on an AIX box to a new eclipse setup on a redhat RedHat box, and the directory structure changed.

Doug Fulford
  • 49
  • 11