Jump to content
  • Advertisement
Sign in to follow this  
HopeDagger

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

This topic is 4340 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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/"+folder+"/"+key+".png") );

// and..

		Image img = parentApplet.getImage( parentApplet.getCodeBase(), "Data/Graphics/"+folder+"/"+key+".png" );


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 only 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.

Share this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
@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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!