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

## 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 on other sites
Is it an applet ?
You may want to provide a policy to get rid of the AccessControlException.
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 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 on other sites
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 on other sites
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 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]

• 9
• 16
• 9
• 13
• 41