Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

access Denied (FilePermission)  RSS feed

 
Sven Habermann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i�m trying to use gif�s ("load.gif" and "store.gif") in an applet, but it won�t work.
I got an "AccessControlException".
How can I fix these exception and use these gif�s for my applet.
Thanks
Sven
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Probably you are just using their names to access them in your applet, this won't work because in this case they'll be treated as File operation. Applets cannot access local file system due to security restrictions. You should convert them (file paths) in the URLs using getCodeBase() or sth.
If this doesn't help, pls post your code here.
HTH,
- Manish
 
Sven Habermann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for yout hint! But it doesn't work, too. Because ImageIcon needs a String, not an URL.
This is my Code:
private class LoadFile extends JPanel {
private JTextField openField = new JTextField("C:\\ ", 10);
private JButton loadButton = new JButton();
private LoadFile() {
setLayout(new FlowLayout());
loadButton.setIcon(new ImageIcon("load.gif"));
loadButton.setEnabled(false);
openField.setEnabled(false);
add(openField);
add(loadButton);
}
}
This error occurs:
ava.security.AccessControlException: access denied (java.io.FilePermission load.gif read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.lang.SecurityManager.checkRead(SecurityManager.java:887)
at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:486)
at sun.awt.SunToolkit.getImage(SunToolkit.java:500)
at javax.swing.ImageIcon.<init>(ImageIcon.java:81)
at javax.swing.ImageIcon.<init>(ImageIcon.java:107)
at TPSimulator$LoadFile.<init>(TPSimulator.java:252)
at TPSimulator$Input.<init>(TPSimulator.java:152)
at TPSimulator.<init>(TPSimulator.java:34)
at Gui.<init>(Gui.java:48)
at SHSimulationsApplet.<init>(SHSimulationsApplet.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:306)
at java.lang.Class.newInstance(Class.java:259)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1775)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
at sun.applet.AppletPanel.run(AppletPanel.java:292)
at java.lang.Thread.run(Thread.java:536)
Thanks for yout help!
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ImageIcon does have this overloaded constructor which takes an URL.
public ImageIcon(URL location)
HTH,
- Manish
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!