1

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

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)

这对我来说很奇怪,因为音轨在后台播放,但小程序在加载图像时出现问题。我已将该小程序放在服务器上:http ://skibba.strefa.pl/applet/applet.html 如果您想检查。当我尝试从我的 PC 上的硬盘驱动器在浏览器中启动小程序时,我遇到了同样的错误。

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

该小程序在 Eclipse 的 Applet:Viewer 中运行良好 - 没有错误,只有在浏览器中才有问题。

4

2 回答 2

3

这对我来说很奇怪,因为音轨在后台播放,但小程序在加载图像时出现问题。

假设图像和剪辑位于同一目录中,这表明音乐剪辑是URL从“主”位置加载的(对于沙盒小程序来说可以),而图像正在加载File(仅可能在受信任的小程序中,并且不适合我们为小程序提供的资源)。

组织通过 URL 加载图像,它应该可以工作。

于 2013-08-22T21:22:01.210 回答
1

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

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

我希望它有所帮助。

于 2013-08-22T20:58:03.303 回答