Java小程序游戏未授权读取图片 [英] Java applet game has not granted permission to read images

查看:24
本文介绍了Java小程序游戏未授权读取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Welcome, I had problem with launching my applet in browser, after few trys I finnaly had run that, i heard music, but the screen was still white, so i run console and i saw that error:

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 上的硬盘驱动器启动浏览器中的小程序时遇到同样的错误.

It was strange to me because the sound track was playing in background but applet had a problem with loading images. I have put that applet on server: http://skibba.strefa.pl/applet/applet.html If you want to check. I am getting same error as while i was trying to launch the applet in browser from hard drive on my PC.

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

And if i have no permission, so why the music is playing?

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

The applet runs in eclipse's Applet:Viewer well - no errors, only in browser is the problem.

推荐答案

我觉得很奇怪,因为音轨在后台播放,但小程序在加载图像时出现问题.

It was strange to me because the sound track was playing in background but applet had a problem with loading images.

假设图像和剪辑在同一目录中,它表明音乐剪辑正在通过 URL 从主页"位置(对于沙盒小程序可以)加载,而图像是由 File 加载(仅在受信任的小程序中才有可能,不适用于我们为小程序提供的资源).

Presuming the image and clip are in the same directory, it suggests the music clip is being loaded by URL from the 'home' location (OK for a sand-boxed applet) while the image is being loaded by File (only possible in a trusted applet, and not suitable for resources we supply for an applet).

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

Organize to load the image by URL, and it should work.

这篇关于Java小程序游戏未授权读取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆