Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] The dreaded JARs! (Resource loading question)

Started by HopeDagger Jul 6, 2006 at 11:28 PM 2 replies 1k views
Original Post
HopeDagger
HopeDagger
Me again. [smile] I have an applet that needs to load a variety of images from a JAR archive. Unfortunately, these puppies are refusing to be accessed. Here's what I've tried already in an attempt to load the images:

		Image img = parentApplet.getImage( parentApplet.getClass().getClassLoader().getResource("Data/Graphics&#47;"+folder+"&#<span class="java-number">47</span>;"</span>+key+<span class="java-literal">".png"</span>) );

<span class="java-comment">// and..</span>

		Image img = parentApplet.getImage( parentApplet.getCodeBase(), <span class="java-literal">"Data&#<span class="java-number">47</span>;Graphics&#<span class="java-number">47</span>;"</span>+folder+<span class="java-literal">"&#<span class="java-number">47</span>;"</span>+key+<span class="java-literal">".png"</span> );


</pre></div><!--ENDSCRIPT-->

When I simply provide the data WITHOUT a JAR file, simply placed in the same directory, it works beautifully, so I don't think it's a directory issue. It &#111;nly likes to bork when I package the information in a JAR archive. The rest of the applet loads just fine.

I'm wide open to ideas, and as always: thanks in advance. You Java folks rock. [smile]


EDIT: Oh, darn. Pretend those warped HTML codes GD.NET converted are really forward slashes.</code></pre></div>
Addictman
Addictman
Hi!

You're saying your images are within a jar file? If so, is it the same jar archive that contains the code that tries to load them, or is it a different jar file?

Take a look at this thread:

http://www.gamedev.net/community/forums/topic.asp?topic_id=398094

Let us know whether this solves your problem or not. Remember that when you are trying to load things *from* a jar, the "current directory" is the classpath, and not necessarily the current directory (the directory where the jar you call things from is located).
Development blog, The Omega Sector -- http://www.omegasector.org
markr
markr
You may wish to try using a path with a leading "/" on it. Remember that JAR filenames are probably case sensitive.

I've looked at some of my code (which is J2ME Midlet not an Applet), and that's what I'm doing. From memory, I think that if you omit the leading "/", it probably doesn't work.

What exception are you getting?

Mark
HopeDagger
HopeDagger
@Addictman: That did the trick. Thanks a lot for the linkage. [smile]

@Mark: It wasn't the leading forward slash, but your help is still appreciated. (and your rating is alread maxed, so 'thanks' will have to suffice, hehe)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.