This discussion is archived
5 Replies Latest reply: Mar 9, 2011 3:09 PM by 843990 RSS

Accessing Resources through getResource() Not Working

843990 Newbie
Currently Being Moderated
I have created a JAR file using Eclipse. The JAR includes my class files, and few JPG images.
I'm trying to access those JPG images through one of the classes in the JAR.

All classes and images are found on the top level of the JAR (I mean, not inside a folder).

I've read that accessing resources in this manner is done using this.getClass().getResource(String path).

I wasn't sure what the path should be like, so I've tried the three possible options I had in mind:

-Sending the image name as it is (for example, "next.jpg")
-Sending the name, with a slash before it ("/next.jpg")
-Sending the name with two backslashes before it.

I'm checking after each of these calls whether url is null, and it is always null. What should I be doing differently?

I appreciate your help.


  • Correct Answers - 10 points
  • Helpful Answers - 5 points