应用程序在某些操作系统上崩溃(使用AWT Swing)

时间:2013-06-07 21:51:35

标签: java swing jenkins noclassdeffounderror windowbuilder

我在JAVA中使用Window Builder和Eclipse编写了一个带有GUI的应用程序。更具体地说,该应用程序是一个问卷,其中问题从数据库中检索,答案也存储在那里。

我使用了Window Builder中的标准SWING组件,但是为了处理事件和更改颜色/字体,我使用了AWT。

问题在于,虽然应用程序在大多数系统上运行正常(在我的Windows 7上从未崩溃),但它崩溃了 - 在其他一些系统上意外地抛出了以下内容:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError:....

如果可执行文件.jar文件是由JENKINS构建的,那么这通常发生在linux和MAINLY上。

在互联网上搜索了一段时间后,我看到混合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)

1 个答案:

答案 0 :(得分:2)

AWT是Swing的一部分...某些类是共享的,而Swing工具包实际上只是建立在AWT上。糟糕的想法是混合使用AWT和Swing元素 - 例如,在swing.JPanel中使用awt.Label。

您获得的异常很可能是平台之间的某些不兼容性。例如,如果您在Linux上使用Windows外观,那么它就不会起作用,因为Windows LaF使用仅在Windows上可用的一些元素。

我建议删除所有非重要的花哨东西,坚持使用默认的Java设置。如果这不起作用,那么你需要更详细地调试Exception。