Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getClassLoader().getResource() does not load images

843802May 12 2005 — edited May 17 2005
I am working on converting our application to work with JavaWebStart on JRE 1.4.2_05 and have hit a brick wall and need some insight as to why I am having problems.

When I load an image file using the following code I get the URL object back as expected:

MyClass.class.getResource("image.jpg")

However, when I use any of the below methods to load the image, the URL object returned is always null.

this.getClass().getClassLoader().getResource("image.jpg");
Thread.currentThread().getContextClassLoader().getResource("image.jpg");
MyClass.class.getClassLoader().getResouce("image.jpg");

The first two of the list above are mentioned in the JavaWebStart FAQ http://java.sun.com/products/javawebstart/faq.html#54.
I can honestly find no explicit reference to the working method and why it should work when the others don't. Can anyone here explain why it works when the others don't? I have to change some third party library software to use the first working method if I can't find a reason such as a bug ID telling me I need to upgrade the JRE or something that would explain the logic behind why it is working this way.

Thanks,
Eric Laabs
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2005
Added on May 12 2005
5 comments
1,405 views