Help figure out why my applet won't run on my Mac.
-
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.
-
Answer:
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 http://www.osxfaq.com/tutorials/learningcenter/UnixTutorials/LoseTheMouse/index.ws ). 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).
MadamM at Ask.Metafilter.Com Visit the source
Other answers
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.
GuyZero
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.
MadamM
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.
GuyZero
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.
GuyZero
Hmm... all the files- html, .class, gifs, everything- are in the same directory.
MadamM
I think it might be helpful for you to read about http://www.javaworld.com/javaworld/jw-05-1997/jw-05-security.html. (I'm not joking; it's a term of art.)
Class Goat
Related Q & A:
- Why won't my app run in the IOS simulator?Best solution by Stack Overflow
- Why google map won't show mark to me?Best solution by Stack Overflow
- Why i can't run my yahoo messenger?Best solution by Yahoo! Answers
- My turtle won't open its eyes...help?Best solution by Yahoo! Answers
- Why my attachments won't download?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.