Java applet游戏未授予读取图像的权限

时间:2013-08-22 20:32:07

标签: java permissions applet access-denied accesscontrolexception

欢迎,我在浏览器中启动我的applet时遇到了问题,经过几次尝试后我终于运行了,我听到了音乐,但屏幕仍然是白色的,所以我运行控制台,我看到了这个错误:

Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied ("java.io.FilePermission" "grass.png" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at sun.plugin2.applet.AWTAppletSecurityManager.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 rpg.imgs.loadAndDraw(imgs.java:18)
    at rpg.main.paint(main.java:343)
    at rpg.main.update(main.java:334)
    at sun.awt.RepaintArea.updateComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

对我来说这很奇怪,因为声道是在后台播放,但是applet在加载图像方面遇到了问题。我已将该applet放在服务器上:http://skibba.strefa.pl/applet/applet.html 如果你想检查。当我试图在我的PC上从硬盘驱动器中启动applet时,我得到了同样的错误。

如果我没有许可,为什么要播放音乐?

小程序在eclipse的Applet中运行:查看器很好 - 没有错误,只在浏览器中出现问题。

2 个答案:

答案 0 :(得分:3)

  

对我来说这很奇怪,因为声道是在后台播放,但是applet在加载图像方面遇到了问题。

假设图像和剪辑位于同一目录中,它表示音乐剪辑正由URL从“主页”位置加载(对于沙盒小程序正常),而图像正在加载File(仅适用于受信任的applet,不适合我们为applet提供的资源)。

组织按网址加载图片,它应该有效。

答案 1 :(得分:1)

是应用程序无权从存储png的文件夹中读取的错误的解释。默认情况下,小程序拒绝访问本地目录。您需要签署applet或编辑策略。

http://www.coderanch.com/how-to/java/HowCanAnAppletReadFilesOnTheLocalFileSystem

我希望它有所帮助。