Applet:关闭时触发异常

时间:2011-06-08 22:34:32

标签: java swing exception applet

当我的applet在webbrowser中停止时,我有一种奇怪的行为

Exception in thread "SwingWorker-pool-1-thread-3" java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThread)
    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 sun.applet.AppletSecurity.checkAccess(AppletSecurity.java:214)
    at java.lang.Thread.checkAccess(Thread.java:1330)
    at java.lang.Thread.interrupt(Thread.java:903)
    at java.util.concurrent.ThreadPoolExecutor$Worker.interruptIfIdle(ThreadPoolExecutor.java:844)
    at java.util.concurrent.ThreadPoolExecutor.interruptIdleWorkers(ThreadPoolExecutor.java:994)
    at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:952)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:680)

任何人都可以解释这个问题吗?

杰森


在追踪另一个错误的同时,我将我的代码简化为最小化,并且在此过程中找到了这个例外的错误:

new ImageLoaderWorker(this,background.setCoordinatesCenter(400, 240)).execute();

background包含路径维度等有用的信息。

ImageLoaderWorker如下所示:

public class ImageLoaderWorker extends SwingWorker<ImageIcon, Void> {

@Override
    public ImageIcon doInBackground() {
        System.err.println("do in background");
        return loadImage();
    }

@Override
    public void done() {
        System.err.println("done");
        try {
            if(!sskkWhitePages.containsKey(iich.getName())){
                sskkWhitePages.put(iich.getName(), get());
            }
            iich.transfertImage();
            if(callback != null){
                callback.imageLoaded(iich.getName());
            }
        } catch (InterruptedException ignore) {}
        catch (java.util.concurrent.ExecutionException e) {
            String why = null;
            Throwable cause = e.getCause();
            if (cause != null) {
                why = cause.getMessage();
            } else {
                why = e.getMessage();
            }
            System.err.println("Error retrieving file: " + why);
        }
    }

/**
     * Load the image for the specified frame of animation. Since
     * this runs as an applet, we use getResourceAsStream for 
     * efficiency and so it'll work in older versions of Java Plug-in.
     */
    protected ImageIcon loadImage() {
        //Not really relevant to the problem I think so I skipped it to avoir overloading the question
}

1 个答案:

答案 0 :(得分:1)

我认为这可能是一个JDK错误 - 请参阅此NetBeans bug report

NetBeans错误报告引用了JDK错误ID,并表示它已在Java 6中修复。但引用的JDK错误已无法访问。

如果您的浏览器有一个Java 5插件,这是一个合理的解释,一个合理的解决方案是将插件升级到Java 6。