Jump to content
  • Advertisement
Sign in to follow this  
tprk77

[java] .jar's and loading images: I have no idea

This topic is 4668 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

I'm sure this question is asked alot. I've been googling all over the place trying to figure it out but I can't figure it out. So anyway... I have made my game into a .jar file. I made my game using JBuilder, and everything was just peachy until I tried to put my .jar on my site. No matter what I do, I get a AccessControlException: access denied when I try and load images. I've tried a few different things, putting images in the jar, putting them outside the jar, using getClass().getResource(), using getImage(). I read a bunch of pages on this issue, but to no avail. Basically, I've been stuck for a long time, I need some advice, please.

Share this post


Link to post
Share on other sites
Advertisement
Is it an applet ?
You may want to provide a policy to get rid of the AccessControlException.
Some interesting reading is here:
http://java.sun.com/j2se/1.4.2/docs/guide/security/PolicyFiles.html
http://java.sun.com/j2se/1.4.2/docs/guide/security/spec/security-specTOC.fm.html

Share this post


Link to post
Share on other sites
I'm sorry. Yes, it is an applet, I'm not using java web start or anything. I'm looking at these sites that you posted, but as of right now I don't see how this really helps my situation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
try this:
Image image = (new javax.swing.ImageIcon(this.getClass().getResource(filepath))).getImage();

it's an old line in an old code of mine... i hope it's a working one ;)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The problem lies in trying to access resources (obviously) in an applet. Java is designed so that some malicious, or even innocent, programmer can't access your hard drive and say...delete your system folder.

I personally have had a similar problem with a data file, not images, but this site has some helpful information about security issues with applets. Hopefully that helps some.

Share this post


Link to post
Share on other sites
Put your resources at the src folder of your applet (that is, immediately outside the packages' folders), and load your resources like this:


URL url = MyClass.class.getResource("/myImage.png"); // Dont't forget the slash besides the filename
//Use the URL to load your resource. You can also use getResourceAsStream()


I believe this might work, I don't have the time to test it right now, so if anyone can prove me wrong, correct me please >_<

Son Of Cain

[edit: BTW, I mean to do that over a jar file]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!