I compile with javac helloswing.java but cannot run with java swingtutorial.helloswing as it said Exception in thread main NoClassDefFoundError. Could not find main class
I just added classpath to c:…\rt.jar but still java -cp . swingtutorial.helloswing cannot find main why ?
package swingtutorial;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class helloswing extends JFrame {
public helloswing() {
setTitle("Hello Swing");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
helloswing ex = new helloswing();
ex.setVisible(true);
}
});
}
}
You need to specify the classpath. Try with