我用ECLIPSE写了一个APPLET程序,用ECLIPSE和Appletviewer运行都没问题,但直接运行HTML文件就无法运行.JAVA控制台显示
java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.io.FilePermission image/0.jpg 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 GameContainer.init(GameContainer.java:101)
at GameContainer. <init> (GameContainer.java:46)
at appletGame. <clinit> (appletGame.java:5)
... 11 more
貌似是无法访问本地资源,但我打包也试过了还是解决不了问题.
HTML文件:
<HTML>
<TITLE> GAME </TITLE>
<applet archive= "applet.jar "
code= "appletGame.class "
codebase= ". "
width=720 height=576>
</applet>
</HTML>
JAVA程序太长了,我是想把原来在WINDOWS下运行的拼图游戏移植到网页里.望了解情况的高手指点啊~~~~
------解决方案--------------------
applet不能访问本地资源,你可能是读取了本地IO资源。
如果要访问的话,需要通过证书认证。可以自己生成一个,然后让用户通过执行。
------解决方案--------------------
在机器主目录创建.java.policy文件:
grant{
permission java.io.FilePermission "image/0.jpg ", "read ";
};
如果还有其他Caused by: java.security.AccessControlException: access denied (java.io.FilePermission image/0.jpg read)
错误,请添加相似的策略项