Java window builder: runtime error

user1315621 picture user1315621 · Jun 21, 2016 · Viewed 8.5k times · Source

I create very simple Gui using WindowBuilder plugin for Eclipse. I'm using Swing (maybe a problem?) I've got plenty of runtime errors:

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

Code:

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");
    }
}

Please note that jgoodies is included in the referenced libraries.

Answer

tapsey picture tapsey · Nov 1, 2016

Make sure the project contains both jgoodies-common-x.x.x.jar and jgoodies-forms-x.x.x.jar

If you create a new window project and add a jgoodies component to the UI you will get the jar file, then you can just copy it into your original project and reference it.