Java Applet 中 invokeLater() 上的 NoClassDefFoundError

发布于 2024-09-24 08:34:11 字数 785 浏览 1 评论 0原文

我有一个使用 NetBeans 构建的小程序,称为 AKApplet。它在 IDE 中运行良好,但是当我将其放入网页中时,它会抛出以下错误:

Exception in thread "Thread-15" java.lang.NoClassDefFoundError: AKApplet$2
    at AKApplet.run(AKApplet.java:675)

小程序使用 run() 方法在后台加载一些数据,同时保持 UI 响应。相当标准的东西。在第 675 行,加载数据后,我尝试使用 invokeLater() 更新 UI 组件:

public void run() {

    // ... data loads ...

    // line 675:
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            userMessages.setText("Data loaded.");
            panelList.setVisible(true);
            validate();
            }
    });

}

我尝试更新的组件是 userMessages,一个 JLabel 和一个面板 panelList。但我认为事情还没有发展到那么远。

有谁知道会发生什么?此时小程序已加载,可以看到组件并已更新等。

I have an applet I've built using NetBeans, called AKApplet. It runs fine in the IDE, but when I put it in a web page it throws the following error:

Exception in thread "Thread-15" java.lang.NoClassDefFoundError: AKApplet$2
    at AKApplet.run(AKApplet.java:675)

The applet uses the run() method to load some data in the background while keeping the UI responsive. Pretty standard stuff. At line 675, after the data has been loaded, I'm trying to update the UI components using invokeLater():

public void run() {

    // ... data loads ...

    // line 675:
    javax.swing.SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            userMessages.setText("Data loaded.");
            panelList.setVisible(true);
            validate();
            }
    });

}

The components I'm trying to update are userMessages, a JLabel and panelList which is a Panel. I don't think it's getting that far however.

Does anyone know what might be happening? At this point the applet has loaded and the components can be seen and have been updated, etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无畏 2024-10-01 08:34:12

确保您不仅部署 AKApplet.class,还部署 AKApplet$1.classAKApplet$2.class 等。

Make sure you're deploying not only AKApplet.class, but also AKApplet$1.class, AKApplet$2.class, etc.

陌路黄昏 2024-10-01 08:34:12

我想我不明白 $ 类指的是什么。只有一个 AKApplet 类,没有内部类。也没有静态定义。

我确实定义了另外两个类,但它们是单独的类:

class ThreadFlags { /*...*/ }

class DeleteButton extends JLabel { /*...*/ }

另外,我已经验证它们位于根级别的 AKApplet.jar 文件中:

META-INF/MANIFEST.MF
META-INF/AKAPPLET.SF
META-INF/AKAPPLET.DSA
META-INF/
AKApplet.class
DeleteButton.class
ThreadFlags.class

更新: 好的,我找到了 AKApplet$。 NetBeans 项目的 /build/classes/ 目录中的类文件。我添加了它们,并且有效。感谢您的帮助。有人能给我简要解释一下这些文件是什么吗? 正如我所说,我没有定义任何内部类...

I guess I don't understand what the $ classes refer to. There is only a single AKApplet class, no inner classes. There are no static definitions either.

I do have two other classes defined, but they are separate classes:

class ThreadFlags { /*...*/ }

class DeleteButton extends JLabel { /*...*/ }

Also, I've verified that they are in AKApplet.jar file at the root level:

META-INF/MANIFEST.MF
META-INF/AKAPPLET.SF
META-INF/AKAPPLET.DSA
META-INF/
AKApplet.class
DeleteButton.class
ThreadFlags.class

Update: Ok, I found the AKApplet$.class files in the /build/classes/ directory of the NetBeans project. I added them, and it works. Thanks for your help. Can someone give me a brief explanantion of what those files are? As I said, there are no inner classes that I've defined...

蘸点软妹酱 2024-10-01 08:34:12

AKApplet 的第二个内部类中是否有可能引发任何类型异常的静态定义?

在确保类文件存在并且位于类路径上之后,静态初始化程序中的异常是导致 NoClassDefFoundErrors 的最常见原因。

Are there any static definitions in the second inner class of AKApplet that could throw any kind of exception?

Exceptions in the static initializer are the most common cause for NoClassDefFoundErrors after you have made sure that the class file exists and is on the classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文