Click to See Complete Forum and Search --> : How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?


sangeethraj
September 24th, 2009, 10:44 PM
Hi,
I am new to this website.
I am learning java.I have done a simple program as below

class Firstpgm
{
public static void main(String args[])
{
System.out.println("Hello");
System.out.println("Welcome to Java World");
}
}

I have kept the program in the following path C:\NiitJavaPgm.
I have set the class path as C:\NiitJavaPgm;C:\Program Files\Java\jdk1.5.0\bin;.;

This program is compiled properly and the class file is created in the same location but while running it show the following error.

Exception in thread "main" java.lang.NoClassDefFoundError:Firstpgm

Please help me asap.

keang
September 25th, 2009, 05:08 AM
What are you typing at the command line to compile the program and what are you typing to run it?

sangeethraj
September 25th, 2009, 05:34 AM
Hi Keang,
For compilation, javac Firstpgm.java
For run, java Firstpgm

lalitgu
September 25th, 2009, 05:46 AM
Hi,

Are you running the program (java Firstpgm) from the same directory where the Firstpgm.class file is there?

dlorde
September 25th, 2009, 05:53 AM
Your class must be declared 'public' if you want to run it.

I have set the class path as C:\NiitJavaPgm;C:\Program Files\Java\jdk1.5.0\bin;.;You shouldn't have the Java bin directory on your classpath, the classpath is for finding .class and .jar files, not executables.

He who is ashamed of asking is ashamed of learning...
Danish proverb

sangeethraj
September 25th, 2009, 10:10 AM
Your class must be declared 'public' if you want to run it.

You shouldn't have the Java bin directory on your classpath, the classpath is for finding .class and .jar files, not executables.

He who is ashamed of asking is ashamed of learning...
Danish proverb


Could you tell me how to set the classpath

sangeethraj
September 25th, 2009, 10:12 AM
Hi,

Are you running the program (java Firstpgm) from the same directory where the Firstpgm.class file is there?

Yes the class file is in the same directory only

lalitgu
September 25th, 2009, 10:59 AM
You have already set the classpath as mentioned in your post. You need to remove the Java bin directory from the CLASSPATH. Changing the CLASSPATH will not help in running the program.

For running the class, you need to declare the class Firstpgm as public.

Could you tell me how to set the classpath

dlorde
September 25th, 2009, 12:01 PM
Could you tell me how to set the classpath
Try this (http://tinyurl.com/djybj4).

One can think effectively only when one is willing to endure suspense and to undergo the trouble of searching...
J. Dewey