I'm fairly new to Java, trying to make my first significant Japplet. It's a
small BlackJack game with a swing interface. I'm trying to display GIF
images of the card faces, but I can't get the GIF images to load. I keep
getting security exceptions saying the applet doesn't have read access.
I've got the class files and images packaged in a JAR file. The image files
are stored in a folder named "cardfile". Here's the java code I use to read
the images:
Toolkit kit = Toolkit.getDefaultToolkit();
String blankCard = "cardfile/blank.GIF";
Image blankCardImage = kit.getImage(blankCard);
I launch the applet with this HTML from the same directory as the JAR file:
<applet code="Hello1.class" archive="Hello1.jar" width="800"
height="600"> </applet>
I can run my applet from AppletViewer within my IDE (Netbeans), but I can't
run it from disk or my webserver. Here are the runtime exceptions I keep
getting:
java.security.AccessControlException: access denied
(java.io.FilePermission cardfile/blank.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 GUItype.<init>(GUItype.java:61)
at Hello1.init(Hello1.java:66)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-Hello1.class"
java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Like I said, I'm new to Java, but best I can tell it says I don't have file
permission to read the GIF files. I thought that Applets could read files
stored within the same codebase that they were launched from, without any
special security settings. When I remove the attempts to read the images,
the applet works fine. Any ideas?
Andrew Thompson - 27 Jul 2005 09:25 GMT
> I'm fairly new to Java, ..
I hope the fact that you're multi-posting means you
are also new to groups and simply don't understand.
<http://www.physci.org/codes/javafaq.jsp#xpost>

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Not Affiliated With Futurama Brass Knuckle Co.
Ed - 28 Jul 2005 05:08 GMT
>> I'm fairly new to Java, ..
>
> I hope the fact that you're multi-posting means you
> are also new to groups and simply don't understand.
> <http://www.physci.org/codes/javafaq.jsp#xpost>
No, actually I did it on purpose because I knew I would have a higher
probability of getting a correct answer that way.
Andrew Thompson - 28 Jul 2005 05:48 GMT
> "Andrew Thompson" <SeeMySites@www.invalid> wrote in message
..
>> I hope the fact that you're multi-posting means you
>> are also new to groups and simply don't understand.
..
> No, actually I did it on purpose because I knew I would have a higher
> probability of getting a correct answer that way.
That won't work for long..
<http://groups.google.com.au/group/comp.lang.java.programmer/msg/10de9f6b8684aa75>

Signature
Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
Now Interactive! Joystick Controls Fry's Left Ear.
Tor Iver Wilhelmsen - 27 Jul 2005 15:22 GMT
> Toolkit kit = Toolkit.getDefaultToolkit();
> String blankCard = "cardfile/blank.GIF";
> Image blankCardImage = kit.getImage(blankCard);
This will try to get the image from the local filesystem.
Look into Class.getResource() and the ImageIcon class.
Ed - 28 Jul 2005 05:02 GMT
> Look into Class.getResource() and the ImageIcon class.
Thanks, that did the trick! The Applet tutorial and the Icon tutorial
worked me through it today.