Java Applet 中 invokeLater() 上的 NoClassDefFoundError
我有一个使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您不仅部署
AKApplet.class
,还部署AKApplet$1.class
、AKApplet$2.class
等。Make sure you're deploying not only
AKApplet.class
, but alsoAKApplet$1.class
,AKApplet$2.class
, etc.我想我不明白 $ 类指的是什么。只有一个 AKApplet 类,
没有内部类。也没有静态定义。我确实定义了另外两个类,但它们是单独的类:
另外,我已经验证它们位于根级别的 AKApplet.jar 文件中:
更新: 好的,我找到了 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:
Also, I've verified that they are in AKApplet.jar file at the root level:
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...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.