Why would an applet work fine on my school's Windows computers, only to throw "java.security.AccessControlException: access denied (java.io.FilePermission filename.gif read)" when I attempt to run it on my Mac? This is using a lot of Java stuff I'm quite unfamiliar with, so be prepared to talk down to me. The thing-I-don't-understand in question is mostly something called MediaTracker, if that rings any bells. Many more details inside and upon request.

So, I'm working on a CS project (I'm in my second year of HS computer science) that basically involves creating our own game. Fun little end of semester project, except we're running short on time (AP/IB exams for me and my partner got in the way). Our teacher provided us with a base framework for dealing with applets and images and threads and such which makes things look nicer, but which are nothing we're familiar with. I can *use* all this unknown stuff, but fixing it is beyond me. Currently, our program (such as it is) runs fine on the computers at school, using whatever applet viewer JCreator uses (I assume nothing special?) When I try to open the HTML file with the applet at home in Firefox, I get the error message I wrote out before. Same thing happens in Safari. The problem (based on the Java console I found in the Firefox Web Developer extension) is on this line:

myImage = Toolkit.getDefaultToolkit().getImage("filename.gif");

I am happy to look for and copy out anything else, including the full error console readout, but I am hesitant to just put the whole dang thing up because frankly I would imagine it's overkill. The main thing is it works fine a school; I just can't figure out what's wrong with it at home. Incidentally, the reason I want it to work on my laptop so bad is so I can work on it more easily outside of class. I'll probably go kick my brother off our home Windows desktop (and will report back if that solves/doesn't solve the problem), but for the future mobility => maximized workin' time. So thank you a thousand times if you can figure this out for me, as googling has simply made me more aware of how far above my head I am working.

This is the result of the Java VM not being able to access the file in question.

Just a guess, but what's happening might be that the Java applet is trying to open the file "filename.gif", which it is searching for in your current working directory - that is, the directory that Firefox is running in, not the directory that your source code is in.

Try providing the full (Unix) path to "filename.gif", if you know it. (If you don't know what I'm talking about, try reading through this tutorial ). If your image is in a directory named "src" in your homedir, the path would be /Users/yourusername/src/filename.gif .

If that still doesn't work, it may be a permissions problem. Navigate to the directory using Terminal.app, then enter the command "chmod a+r filename.gif" and try again. (This command sets the Unix "read" permission bit for all users - it allows everyone to read that file).posted by ArbiterOne at 10:43 PM on May 19, 2008

Applets run from the filesystem often have tighter security restrictions than ones run over the internet oddly enough. Applets get no file system access and since resources are loaded from the same place that the applet came from you end up not being able to access anything. The simple fix would be to run a web server locally and load the applet via that. The more complex fix is to create a custom security manager or something. Or sign the applet. But just turn on web sharing, stick the applet files in your web sharing directory then load it via "the web" and that should work around it.posted by GuyZero at 10:45 PM on May 19, 2008

I changed the path to the file, using the full /Users/username/whatever path, and oddly enough, I no longer have an error come up for the first image. Thing is, right after the one that was coming up as a problem is another two images treated the same way. I changed the paths on those and they still come up with the same error. I don't seem to have forgotten a semi-colon or left some quotes open or anything, so I dunno why the first one was fixed and not the others. I will continue to mess with it.

GuyZero, something along those lines was what little I gleaned from my googling- basically, that running an applet off the filesystem was an annoying pile of security errors. Where, precisely, might I find my websharing folder? (Did I mention I'm new to Macs?). I assume that will work fine sans-Internet, as that will be how I'll be working at school.posted by MadamM at 10:58 PM on May 19, 2008

Go to System Preferences > Sharing and enable "Web Sharing". Your subsite (http://192.168.0.1/~username) will have its files served from the Sites directory under your home directory.posted by GuyZero at 11:07 PM on May 19, 2008

The applet security manager may allow you to load files from the same directory that holds the html file and apples .class files but probably won't let you access other directories.posted by GuyZero at 11:08 PM on May 19, 2008

Hmm... all the files- html, .class, gifs, everything- are in the same directory.posted by MadamM at 11:18 PM on May 19, 2008

Tags

Share

About Ask MetaFilter

Ask MetaFilter is a question and answer site that covers nearly any question on earth, where members help each other solve problems. Ask MetaFilter is where thousands of life's little questions are answered.