class not found error...

Whenever i am trying to execute my program, the run time exception arises saying “Exception in thread “main” java.lang.NoClassDefFoundError”. This happens for every program i try to execute. There are no compile time errors. But while executing, this error occurs. Has this got to do anything with the path settings? Or is this something else…? Please help. All my programs are stuck at execution… :frowning:

This is one of the program’s that i’m trying to execute which didnt.

import javax.swing.*;
public class NewGui
{
public static void main(String[] args)
{
JFrame frame=new JFrame();
JButton button=new JButton(“Click Me”);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(button);
frame.setSize(300,300);
frame.setVisible(true);
}
}

It compiled but didn’t execute.

The command i used to compile was

javac NewGui.java

and the command to execute was

java NewGui

Also, Under the environment variables option, we got two options. One is a CLASSPATH and the other one is Path. I edited the Path section and added the following two paths:

C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\Java\jdk1.6.0\lib;

So is this fine or do I need to add some other paths also?

Please help…

You have to tell java where to find your classes and additional libraries by adding the commandline option “-cp <paths sparated by ;>” If you are on linux, use “:” as separator instead. In your case you probably only have to add the current directory, so try:


java -cp . NewGui

It sounds like you are using the command line in windows. If so you will need to execute those 2 commands javac and java from the dir the source files are in.