简体   繁体   中英

NoClassDefFoundError when developing a basic java SWING app

I'm learning about SWING on intellij. I made a quick app on the GUI designer that contains a button. I compiled it just fine but whenever I run it it throws this error

Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/uiDesigner/core/GridLayoutManager

Here's the code (I run this file from another main file)

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Created by Leon_Clemente on 6/3/15.
 */
public class myFirstTest extends JFrame {
    private JTabbedPane tabbedPane1;
    private JPanel panel1;
    private JButton browseButton;
    private JButton uploadButton;
    private JCheckBox checkBox1;
    private JCheckBox checkBox2;

    public myFirstTest() {
/*
        browseButton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
            }
        });
*/
        setVisible(true);
    }

    private void createUIComponents() {
    }
}

So I read on the forums and the only thing I could relate this problem with is that my running classpath is not the same than my compiling classpath(?) I still don't exactly get the idea though.

forms_rt.jar contains GridLayoutManager class and this jar is located in (IntelliJ IDEA Root)\\lib. Search for this jar in compile environment.

Add this jar to the class path.

How to set the classpath - setting the path of a jar file

I think you forgot to make main method

Create a new class in same package where myFirstTest is present and try this code:

 public class Main{
     public static void main(String[] args) {

      myFirstTest  myfirst = new myFirstTest();
      myfirst.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      myfirst.setSize(400,400);
      myfirst.setVisible(true);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM