Getting NullPointerException when i read a image from jar file

Hi All,

I downloaded a jar using webstart and it contains main method and i specified in the resource tag and in a application-desc tag as below.

my jnlp file contains like,

<resources>

<j2se version="1.5+"/>

<jar href="xx.jar" part="client" main="false" download="eager"/>

<jar href="yy.jar" part="client" main="true" download="eager"/>

</resources>

<application-desc main-class="com.Startmain"/>

</application-desc>

It finds the main method in jar file yy.jar and started to execute well. And i am accessing the image which is in jar using getSystemResource() method in

"ClassLoader" class as below,

URL url = ClassLoader.getSystemResource("com/images/" + "logo.gif" );

Image image = Toolkit.getDefaultToolkit().getImage( url );

ImageIcon imageIcon = new ImageIcon( image );

But in getimage(url) method i am getting "java.lang.NullPointerException" but the image present in that path in the jar

as i mentioned.

can anyone help me plese.

Thanks

malert.

[1126 byte] By [Malerta] at [2007-11-27 8:49:49]
# 1

GetSystemResources() will only return resources available on the system classpath (Loadable by the default ClassLoader).

Jar files listed in a JNLP file are loaded by the JNLPClassLoader, and are not system resources.

You ned to use the curent classloader, or the "ContextCLassLoader" by either using:

url = this.getClass().getClassLoader().getResource("..."); , or

url = Thread.currentThread().getContextClassLoader().getResource("...");

/Andy

dietz333a at 2007-7-12 20:59:40 > top of Java-index,Desktop,Deploying...
# 2

I've had to use getResourceAsStream(...) and use an input stream to get resources out of a jar. Unfortunately the URL (if you look at it in a debugger) turns out to be not a real file-path that new File(...) or getImage(...) can get to.

getResourceAsStream works fine though -- you'll find that Toolkit also has the same getImage methods for InputStreams.

garrytana at 2007-7-12 20:59:40 > top of Java-index,Desktop,Deploying...