我已经使用带有 Eclipse 的 Window Builder 编写了一个带有 GUI 的 JAVA 应用程序。更具体地说,该应用程序是一个问卷调查,其中问题是从数据库中检索的,并且答案也存储在那里。
我使用了 Window Builder 中的标准 SWING 组件,但为了处理事件和更改颜色/字体,我使用了 AWT。
问题是,尽管该应用程序在大多数系统上运行良好(在我的 Windows 7 上从未崩溃过),但它崩溃了 - 在其他一些系统上意外抛出以下内容:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:....
如果可执行 .jar 文件是由 JENKINS 构建的,这通常发生在 linux 上。
在互联网上搜索了一段时间后,我读到混合 SWING 和 AWT 不好,但是在尝试从我的代码中删除所有 AWT 包之后,我无法操作一些简单的细线(字体颜色和尺寸)导入了 AWT。
我在我的代码中的导入列表下方发布
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Image;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Toolkit;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.IOException;
import javax.swing.JComboBox;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
由于 SWING 与 AWT 一起工作的一些失败,是否会引发这样的异常?如果是这样,有没有办法让我可以用 SWING 操纵一切?
提前致谢!
编辑抛出的异常是
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: wBPGui/Demographics/CurrentSkill$17
at wBPGui.Demographics.CurrentSkill.<init>(CurrentSkill.java:414)
at java.awt.AWTEventMulticaster.keyPressed(AWTEventMulticaster.java:250)
at java.awt.Component.processKeyEvent(Component.java:6463)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2820)
at javax.swing.JComboBox.processKeyEvent(JComboBox.java:1417)
at java.awt.Component.processEvent(Component.java:6282)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1895)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:762)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1027)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:899)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:727)
at java.awt.Component.dispatchEventImpl(Component.java:4731)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:702)
at java.awt.EventQueue$4.run(EventQueue.java:700)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)