• Dear Guest, Please do NOT forget to join our JAVA JOBS (ONLY) FACEBOOK GROUP to be aware of latest JAVA openings, and you may also post any JAVA related queries/jobs.

How to eliminate Exception in thread main java.lang.NoClassDefFoundError ?

#1
Hi,

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.
 
#2
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Check class name and file name same or not. If class name and file name different, then this exception raises in this case.
 
#6
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Hi Sangeeth,

Check what palaniappan given that also gives that error
 
#7
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Hi,

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.
hey set CLASSPATH=c:\NiitjavaPgm;.
PATH=c:\ProgramFiles\Java\jdk1.5.0\bin;.
Now u execute the program. Remember to save the file with the class name. Hope this will be helphful
 
#8
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Check ur ProgrammeName(ClassName) and the name you had saved with(.java) file are same or not if it is then compile and run your programme by placing it in drive/jdk folder name/bin i.e(c:/prog miles/java/jdk1.5/bin).

it will be..................
 
#9
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

hey set CLASSPATH=c:\NiitjavaPgm;.
PATH=c:\ProgramFiles\Java\jdk1.5.0\bin;.
Now u execute the program. Remember to save the file with the class name. Hope this will be helphful

Hi Sushilk,
Thanks a lot.
Its working now.

Thanks for everyone who sent replies for my query.
 
#10
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Check class name and file name same or not. If class name and file name different, then this exception raises in this case.
Hi I am radhika. You r compiling the program as javac Firstpgm.java, and running the program as java firstpgm.java.
u have to run as java Firstpgm then u will rectify the problem
 
#12
Re: How to eliminate "Exception in thread "main" java.lang.NoClassDefFoundError"?

Hi Friends ,

If you found java.lang.NoClassDefFoundError Exception . when using command line . path not properly configure (or) more than jre has been installed.

If you want run using following steps
javac TestMe.java
java -cp TestMe (or) java TestMe . ( dot is important )


Thanks,
Muthukumar.T
 

Mui

New Member
#14
Hai Friends,
If ur getting Java.lang.No class Default Error that means JVM is not getting the class. So u have to set classpath.
set classpath = %classpath%Enter
 
#16
Hi,

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.

you should set the class path to run java app then it works fine!
but actually what happen here is if you wont set classpath then java command checks the class file in C:\Program Files\Java\jdk1.5.0\lib but the class file resides in somewhere in local sys.

so "set classpath= C:\Program Files\Java\jdk1.5.0\lib;.;" ,
then java looking for class file in current working directory( .; ) and/or default directory ( C:\Program Files\Java\jdk1.5.0\lib; ) .

It works fine, its all as per my knowledge only.
 

Mui

New Member
#17
Just save the file name Firstpgm.java. First thing is that u never save the Program in c folder. save the program in another program. In classpath you save the lib & in path u save bin in path folder then ur program will run
 
Top