gpt4 book ai didi

Java 窗口生成器 : runtime error

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:07:17 25 4
gpt4 key购买 nike

我使用 Eclipse 的 WindowBuilder 插件创建了非常简单的 Gui。我正在使用 Swing(也许是个问题?)我有很多运行时错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/jgoodies/common/base/Preconditions
at com.jgoodies.forms.layout.FormSpec.<init>(FormSpec.java:179)
at com.jgoodies.forms.layout.ColumnSpec.<init>(ColumnSpec.java:147)
at com.jgoodies.forms.layout.FormSpecs.<clinit>(FormSpecs.java:62)
at com.jgoodies.forms.layout.LayoutMap.createRoot(LayoutMap.java:569)
at com.jgoodies.forms.layout.LayoutMap.getRoot(LayoutMap.java:217)
at com.jgoodies.forms.layout.ColumnSpec.decode(ColumnSpec.java:199)
at it.myweb.project.GUI.TestGUI.initialize(TestGUI.java:50)
at it.myweb.project.GUI.TestGUI.<init>(TestGUI.java:39)
at it.myweb.project.GUI.TestGUI$1.run(TestGUI.java:26)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: com.jgoodies.common.base.Preconditions
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 23 more

代码:

import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class TestGUI {

private JFrame frame;
private JTextField textField;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ChatGUI window = new ChatGUI();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the application.
*/
public ChatGUI() {
initialize();
}

/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 1006, 737);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
ColumnSpec.decode("default:grow"),
ColumnSpec.decode("right:max(50dlu;default)"),},
new RowSpec[] {
RowSpec.decode("fill:default:grow"),
RowSpec.decode("bottom:max(30dlu;default)"),}));

JTextArea textArea = new JTextArea();
frame.getContentPane().add(textArea, "1, 1, 2, 1, fill, fill");

textField = new JTextField();
frame.getContentPane().add(textField, "1, 2, fill, center");
textField.setColumns(10);

JButton btnNewButton = new JButton("Invia");
frame.getContentPane().add(btnNewButton, "2, 2, center, center");
}
}

请注意,jgoodies 包含在引用的库中。

最佳答案

确保项目同时包含 jgoodies-common-x.x.x.jar 和 jgoodies-forms-x.x.x.jar

如果您创建一个新的窗口项目并向 UI 添加一个 jgoodies 组件,您将获得 jar 文件,然后您可以将其复制到您的原始项目中并引用它。

关于Java 窗口生成器 : runtime error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37940141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com