Java window builder: runtime error
Asked Answered
V

3

7

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.

Valse answered 21/6, 2016 at 9:12 Comment(1)
Make sure you add the jgoodies jar to the project, it seems like it's missingFermium
C
3

jgoodies jar should be included in runtime classpath of your application. You mention that is is included in referenced libraries, which presumably means that it is on compile classpath, but this is not enough. To include jar on runtime classpath use -cp switch when running java application with command line.

Cathartic answered 21/6, 2016 at 9:25 Comment(7)
Thanks. So how can I do it in Eclipse?Valse
There are several ways of doing that in Eclipse. For example in run configuration of the application go to "Classpath" tab and add jgoodies jar there by clicking on "Add JARs...".Cathartic
In run\debug setting I add jgoodies jar in both boostrap entries and user entries but I still got the same errorValse
what is the name of the jar you have added there?Cathartic
jgoodies-forms-1.8.0.jar and jgoodies-forms-1.8.0-sources.jarValse
ok, you need to include jgoodies-common-1.x.0.jar, most likely 1.8.0 would be correct version. Also you don't need to include jgoodies-forms-1.8.0-sources.jar, but it would not hurt.Cathartic
I just got the same error in Eclipse 2018-12 (with Java 8, WindowBuilder 1.9.1): Adding a FormLayout automatically imported both jgoodies-forms-1.8.0 jars but it didn't add the "common" one, which caused the error. I had to download "JGoodies Common 1.8.1" (jgoodies-common-1.8.1.jar) myself from here, then added it to the Java Build Path (Project - Properties - Java Build Path - Libraries) and it's working. No need to add it to "Run" too (Run - Run Configurations - Classpath).Viceroy
O
9

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.

Ommatophore answered 1/11, 2016 at 1:13 Comment(2)
The "forms" jar was imported automatically (Java 8, Eclipse 2018-12, WindowBuilder 1.9.1) after adding jgoodies' FormLayout but the "commons" one wasn't. I had to download version 1.8.1 from the official homepage.Viceroy
Exactly my problem. ThanksAnder
C
3

jgoodies jar should be included in runtime classpath of your application. You mention that is is included in referenced libraries, which presumably means that it is on compile classpath, but this is not enough. To include jar on runtime classpath use -cp switch when running java application with command line.

Cathartic answered 21/6, 2016 at 9:25 Comment(7)
Thanks. So how can I do it in Eclipse?Valse
There are several ways of doing that in Eclipse. For example in run configuration of the application go to "Classpath" tab and add jgoodies jar there by clicking on "Add JARs...".Cathartic
In run\debug setting I add jgoodies jar in both boostrap entries and user entries but I still got the same errorValse
what is the name of the jar you have added there?Cathartic
jgoodies-forms-1.8.0.jar and jgoodies-forms-1.8.0-sources.jarValse
ok, you need to include jgoodies-common-1.x.0.jar, most likely 1.8.0 would be correct version. Also you don't need to include jgoodies-forms-1.8.0-sources.jar, but it would not hurt.Cathartic
I just got the same error in Eclipse 2018-12 (with Java 8, WindowBuilder 1.9.1): Adding a FormLayout automatically imported both jgoodies-forms-1.8.0 jars but it didn't add the "common" one, which caused the error. I had to download "JGoodies Common 1.8.1" (jgoodies-common-1.8.1.jar) myself from here, then added it to the Java Build Path (Project - Properties - Java Build Path - Libraries) and it's working. No need to add it to "Run" too (Run - Run Configurations - Classpath).Viceroy
B
3

If your project is maven, it is better to add jgoodies as maven dependency:

<dependency>
    <groupId>com.jgoodies</groupId>
    <artifactId>jgoodies-forms</artifactId>
    <version>1.8.0</version>
</dependency>

This solve all problems.

Benzene answered 13/8, 2017 at 13:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.