Edit: Title - java access denied on graphic file

Edit: I didn't realize i didn't finish typing the title before submitting.

I put my applet on the web but it says not initialized and the error is complaining about my graphic. Am i not allowed to have graphics? How can i fix it?

I get an error on my graphic saying permission denied. I am not sure why. How to correct it so my applet works?


java.security.AccessControlException: access denied (java.io.FilePermission gamegraphics\XMfeatherheadsmilie.gif read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkRead(Unknown Source)
at sun.awt.SunToolkit.getImageFromHash(Unknown Source)
at sun.awt.SunToolkit.getImage(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at javax.swing.ImageIcon.<init>(Unknown Source)
at SlotMachine.<init>(SlotMachine.java:42)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

[short version]: Java applets can't access the local file system without special permissions. Your applet should load any files you need from the server.

Comments
Good post :)

I have an html code that calls an applet with a single graphic file but when i load, there's no Java error. I see the orange Java box but my graphic still does not appear. Why?

http://blogfriendlyzone.webs.com/test.html

It's been an hour. I am beginning to think it can't be done. What good is an applet that won't run my programs with pictures?

Does it mean Java can only load basic programs that don't include any File I/O?

Okay. Sorry for that. I forgot to upload the graphic. I don't think that website is very reliable though because they might tend to delete stuff. Is there a way that the applet could still run and just say Image Not Found instead of leaving me hanging as to what's going on? I would prefer it should still run my applet the way it should and just forget about the image that it can't load.

Okay. Sorry for that. I forgot to upload the graphic. I don't think that website is very reliable though because they might tend to delete stuff. Is there a way that the applet could still run and just say Image Not Found instead of leaving me hanging as to what's going on? I would prefer it should still run my applet the way it should and just forget about the image that it can't load.

If your website server is unreliable, you can always test/run your applet locally on your own computer. Getting the syntax correct can be a major hassle till you get the hang of it (not sure I myself have the hang of it yet :)).

Applets absolutely can be used with images and sounds. The syntax can be frustrating though and there are permissions issues that can be a pain until you get the hang of it.

Regarding having it not abort the applet and simply have it fail if it can't load the Image, you need to tell the applet what you want it to do if it can't load the Image. Do that with a try-throw-catch or with a function that throws and Exception:

http://java.sun.com/docs/books/tutorial/essential/exceptions/
http://java.sun.com/docs/books/tutorial/essential/exceptions/throwing.html

And this page. Scroll down to where it describes using images in a Swing Applet.

http://java.sun.com/docs/books/tutorial/uiswing/components/applet.html

This question has already been answered. Start a new discussion instead.