applet抛出一个AccessControlException

applet抛出一个AccessControlException

本文介绍了为什么我的applet抛出一个AccessControlException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个Java小程序,名为游戏,这是我以前从来没有这样做(我总是刚建的独立应用程序)。我的小应用程序工作正常,当我测试它在Eclipse中,但是当我尝试把它放在我的网站,我在控制台中出现以下错误:

  java.lang.reflect.InvocationTargetException
    在com.sun.deploy.util.DeployAWTUtil.invokeAndWait(DeployAWTUtil.java:116)
    在sun.plugin2.applet.Plugin2Manager.runOnEDT(Plugin2Manager.java:3541)
    在sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3072)
    在sun.plugin2.applet.Plugin2Manager $ AppletExecutionRunnable.run(Plugin2Manager.java:1497)
    在java.lang.Thread.run(Thread.java:680)
java.security.AccessControlException:引起拒绝访问(java.util.PropertyPermission user.dir来读)
    在java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    在java.security.AccessController.checkPermission(AccessController.java:546)
    在java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    在java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
    在java.lang.System.getProperty(System.java:667)
    在java.io.UnixFileSystem.resolve(UnixFileSystem.java:118)
    在java.io.File.getAbsolutePath(File.java:501)
    在游戏<&初始化GT;(game.java:117)
    在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
    在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    在java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    在java.lang.Class.newInstance0(Class.java:355)
    在java.lang.Class.newInstance(Class.java:308)
    在sun.plugin2.applet.Plugin2Manager $ 13.run(Plugin2Manager.java:3060)
    在java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:682)
    在java.awt.EventQueue.access $ 000(EventQueue.java:85)
    在java.awt.EventQueue中的$ 1.run(EventQueue.java:643)
    在java.awt.EventQueue中的$ 1.run(EventQueue.java:641)
    在java.security.AccessController.doPrivileged(本机方法)
    在java.security.AccessControlContext $ 1.doIntersectionPrivilege(​​AccessControlContext.java:87)
    在java.awt.EventQueue.dispatchEvent(EventQueue.java:652)
    在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    在java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    在java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    在java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
例外:java.lang.reflect.InvocationTargetException

报告说,访问被拒绝(java.util.PropertyPermission user.dir来读),但我不能揣摩出它试图读一些出用户的文件系统

它还说在游戏<&初始化GT;(game.java:117),但我走进我的文件,并提出了信息输出到行控制台114和它从未被写入。那么我想,也许是在看线117 公开游戏()里面,所以我找了这一点,它是一个鼠标事件侦听器的开始。这是有道理的,我认为这将是一些Java的需要权限读取,所以我删除了这一切,然后删除了所有的良好措施的进口。然后,我既清除浏览器和Java的缓存和重审。同样的错误。


  1. 这是什么意思,我是间preting它不正确?

  2. 当它说,该行117,它是什么线117?

  3. 为什么会变成这样是这样吗?

  4. 我怎样才能解决这个问题?

  5. 如何prevent它的未来?

有关参考,在这里是code为公开游戏()

 公开游戏()抛出MalformedURLException的{    的JPanel板=新棋盘();
    board.setSize(320,320);
    board.setLocation(0,0);    的System.out.println(远得到这个);    片WP1 =新片(wpawn,A2);
...
    一块BK =新片(bking,E8);
    board.add(WP1);
...
    board.add(BK);    wp1.setLocation(wp1.square.getPoint());
...
    bk.setLocation(bk.square.getPoint());    加(板);
    重绘();    addMouseListener将(新MouseAdapter(){
        公共无效鼠标pressed(EVT的MouseEvent){            的for(int i = 0; I< 8;我++){
                对于(INT J = 0; J< 8; J ++){
                    如果(方块[I] [J] .piece!= NULL)
                        的System.out.println(方块[I] [J] .getPointString()+:+方块[I] [J] .piece.type);
                }
            }            点P = evt.getPoint();
            如果(0℃; p.x&放大器;&放大器; p.x&所述; 319&放大器;&放大器; 0℃; p.y&放大器;&放大器; p.y&所述; 319){
                方点击= getSquare(对);
                的System.out.println(起来:+ clicked.getPointString());
                如果(clicked.piece!= NULL){
                    pickedUp = TRUE;
                    pickedUpPiece = clicked.piece;
                }
            }
        }
        公共无效的mouseReleased(EVT的MouseEvent){
            如果(pickedUp){
                点P = evt.getPoint();
                如果(0℃; p.x&放大器;&放大器; p.x&所述; 319&放大器;&放大器; 0℃; p.y&放大器;&放大器; p.y&所述; 319){
                    的System.out.println(下来:+ getSquare(P).getPointString());
                    movePiece(pickedUpPiece,getSquare(p)的.getColumn(),getSquare(p)的.getRow());
                }
                pickedUp = FALSE;
            }
            其他的System.out.println(没有捡到);
        }
    });
}


解决方案

堆栈跟踪的主要输出是:

 在java.io.File.getAbsolutePath(File.java:501)
在游戏<&初始化GT;(game.java:117)

这意味着你的 game.java 文件,在第117行,呼吁 getAbsolutePath()的东西。嵌入在浏览器的Java小程序都不允许访问本地文件系统。

I am trying to build a Java applet, called game, which is something I have never done before (I've always just built standalone applications). My applet works fine when I test it in Eclipse, but when I try putting it on my website, I get the following error in the console:

java.lang.reflect.InvocationTargetException
    at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(DeployAWTUtil.java:116)
    at sun.plugin2.applet.Plugin2Manager.runOnEDT(Plugin2Manager.java:3541)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3072)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
    at java.lang.Thread.run(Thread.java:680)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
    at java.lang.System.getProperty(System.java:667)
    at java.io.UnixFileSystem.resolve(UnixFileSystem.java:118)
    at java.io.File.getAbsolutePath(File.java:501)
    at game.<init>(game.java:117)
    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:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at sun.plugin2.applet.Plugin2Manager$13.run(Plugin2Manager.java:3060)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:682)
    at java.awt.EventQueue.access$000(EventQueue.java:85)
    at java.awt.EventQueue$1.run(EventQueue.java:643)
    at java.awt.EventQueue$1.run(EventQueue.java:641)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:652)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception: java.lang.reflect.InvocationTargetException

It says access denied (java.util.PropertyPermission user.dir read), but I can't figure out where it's trying to read something off the user's file system.

It also says at game.<init>(game.java:117), but I went into my file and made a message output to the console on line 114 and it never got written. I then figured that maybe it was looking at line 117 inside public game(), so I looked for that and it was the start of a listener for a Mouse event. It made sense to me that this would be something that Java would need permission to read, so I deleted all of it and then deleted all the imports for good measure. Then I cleared both Chrome and Java's caches and retried. Same error.

  1. What does this mean, am I interpreting it incorrectly?
  2. When it says that line 117, what is it line 117 of?
  3. Why would this be happening?
  4. How can I fix it?
  5. How can I prevent it in the future?

For reference, here is the code for public game():

public game() throws MalformedURLException{

    JPanel board = new chessboard();
    board.setSize(320, 320);
    board.setLocation(0, 0);

    System.out.println("Got this far");

    Piece wp1 = new Piece(wpawn, a2);
...
    Piece bk = new Piece(bking, e8);


    board.add(wp1);
...
    board.add(bk);

    wp1.setLocation(wp1.square.getPoint());
...
    bk.setLocation(bk.square.getPoint());

    add(board);
    repaint();

    addMouseListener(new MouseAdapter(){
        public void mousePressed(MouseEvent evt){

            for (int i = 0; i < 8; i++){
                for (int j = 0; j < 8; j++){
                    if (squares[i][j].piece != null)
                        System.out.println(squares[i][j].getPointString() + ": " + squares[i][j].piece.type);
                }
            }

            Point p = evt.getPoint();
            if (0 < p.x && p.x < 319 && 0 < p.y && p.y < 319){
                Square clicked = getSquare(p);
                System.out.println("up: " + clicked.getPointString());
                if (clicked.piece != null){
                    pickedUp = true;
                    pickedUpPiece = clicked.piece;
                }
            }
        }
        public void mouseReleased(MouseEvent evt){
            if (pickedUp){
                Point p = evt.getPoint();
                if (0 < p.x && p.x < 319 && 0 < p.y && p.y < 319){
                    System.out.println("down: " + getSquare(p).getPointString());
                    movePiece(pickedUpPiece, getSquare(p).getColumn(), getSquare(p).getRow());
                }
                pickedUp = false;
            }
            else System.out.println("Not picked up");
        }
    });
}
解决方案

The key output of the stack trace is:

at java.io.File.getAbsolutePath(File.java:501)
at game.<init>(game.java:117)

This means that your game.java file, at line 117, is calling getAbsolutePath() on something. Java applets embedded in a browser are not permitted to access the local filesystem.

这篇关于为什么我的applet抛出一个AccessControlException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 22:24