gpt4 book ai didi

java - 为什么我的小程序抛出 AccessControlException?

转载 作者:行者123 更新时间:2023-11-29 05:59:55 25 4
gpt4 key购买 nike

我正在尝试构建一个名为 game 的 Java 小程序,这是我以前从未做过的事情(我一直只是构建独立的应用程序)。当我在 Eclipse 中测试时,我的小程序工作正常,但是当我尝试将它放在我的网站上时,我在控制台中收到以下错误:

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

它说 access denied (java.util.PropertyPermission user.dir read) ,但我无法弄清楚它试图从用户文件系统中读取某些内容的位置。

它还说 at game.<init>(game.java:117) ,但我进入了我的文件并在第 114 行向控制台输出了一条消息,但它从未被写入。然后我想也许它正在查看 public game() 中的第 117 行,所以我寻找它,它是鼠标事件监听器的开始。对我来说,这是 Java 需要许可才能读取的内容,所以我删除了所有内容,然后删除了所有导入以备不时之需。然后我清除了 Chrome 和 Java 的缓存并重试。同样的错误。

  1. 这是什么意思,我是不是理解错了?
  2. 当它说第 117 行时,第 117 行是什么?
  3. 为什么会这样?
  4. 我该如何解决?
  5. 以后我该如何预防?

作为引用,这里是 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");
}
});
}

最佳答案

堆栈跟踪的关键输出是:

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

这意味着您的 game.java 文件在第 117 行调用了 getAbsolutePath()。浏览器中嵌入的 Java 小程序不允许访问本地文件系统。

关于java - 为什么我的小程序抛出 AccessControlException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10568345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com