Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FilePermission on ImageIcon(String)?!?

1 view
Skip to first unread message

Greg Faron

unread,
Jan 10, 2001, 7:26:46 PM1/10/01
to
Greg Faron wrote:
> java.security.AccessControlException: access denied
> (java.io.FilePermission aTLH.gif read)
^
Yes, this is a posting typo, not a bug.
It should have read "aTLHS.gif" in my post. Sorry.

--
-Greg

Greg Faron

unread,
Jan 10, 2001, 7:23:21 PM1/10/01
to
Has anyone come across a FilePermission problem when trying to
instantiate a simple JButton with an ImageIcon in an applet? I have
a GIF in the same directory as the applet class (no JARs here) and
it's wide open read permissions (-rw-rw-r--). From the init method
below, I receive the error further below. I didn't get this when
working with an application...

--
-Greg

public void init()
{
ImageIcon aTLHS = new ImageIcon("aTLHS.gif");
this.applyToLeftHandSide = new JButton(aTLHS);

this.add(this.applyToLeftHandSide);
} // ends init(void)


java.security.AccessControlException: access denied
(java.io.FilePermission aTLH.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 SolveLinearProblemApplet.init(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

William Brogden

unread,
Jan 11, 2001, 9:38:10 AM1/11/01
to

Greg Faron wrote:
>
> Has anyone come across a FilePermission problem when trying to
> instantiate a simple JButton with an ImageIcon in an applet? I have
> a GIF in the same directory as the applet class (no JARs here) and
> it's wide open read permissions (-rw-rw-r--). From the init method
> below, I receive the error further below. I didn't get this when
> working with an application...
>
> --
> -Greg
>
> public void init()
> {
> ImageIcon aTLHS = new ImageIcon("aTLHS.gif");

This statement says to get aTLHS.gif from the current
directory of the local file system. No wonder you get
a file permission error.

To get a file off the server you have to use a URL and
get an InputStream.

--
WBB - wbro...@lanw.com
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP
ISBN 0-7821-2809-2

Greg Faron

unread,
Jan 11, 2001, 1:09:33 PM1/11/01
to
William,

I've also tried the following code, but it gave me the same
FilePermission error message. Any ideas?

Greg

public void init()
{
URL url = null;
try
{ url = new URL(getCodeBase() + "/aTLHS.gif"); }
catch(MalformedURLException e)
{ System.err.println("failed"); }
ImageIcon aTLHS = new ImageIcon(url);
} // ends init(void)


Furthermore, my earlier post was a direct derivation from the samples
given at Sun
<http://developer.java.sun.com/developer/codesamples/javax.swing/234.html>

Sun:
ImageIcon icon = new ImageIcon("image.gif");
JButton button = new JButton(icon);


William Brogden wrote:

0 new messages