Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What causes the error: java.lang.NoClassDefFoundError

Status
Not open for further replies.

MarkAA

Programmer
Nov 29, 2001
6
GB

I've re-built my PC but now have a bity of silly error, but my brain is dead so thought I would try the easy way out. Please tell me Why" this error occurs!!!1

I can compile any java application on my PC, but when I try to run it I get the following runtime error!!!!

eg:

java C:\java\app\MyApp

gives the error:

Error: java.lang.NoClassDefFoundError:
c:\java\App\MyApp.java


Please help! Many thanks in advance!!
 
The java.lang.NoClassDefFoundError error is basically classpath problem...maybe try setting the classpath w/%JAVA_HOME%/lib/tools.jar ?

If that doesn't work try...

java -cp C:\java\app\ MyApp

Hope this helps..
 
What JVZ said is right u have to set path where u have ur compiled class java files (class files).

In XP you have to set in enviroment variables class path as folder name not as tools.jar.

so it depends on ur environment

let us know which environment ur working so we solve easily


 
Thanks for your help guys! Muchos appreciated!!
I have tried the obvious, but still have issues.

I am using PC with NT 4.0 Workstation loaded, and I have the following environment variables set (My Computer Environment, Proprties, Environment, System Vaiables),

J2EE_HOME=c:\j2sdkee1.3.1
JAVA_HOME=c:\j2sdk1.4.0
claspath=%JAVA_HOME%\lib\*.jar;%J2EE_HOME%\lib\*.jar;c:\xerces-2_0_2\*.jar

I still get the same error. Any ideas!! :-(
 
Cheers guys!! I had a play usign what you said and can now get my apps to compile and runn. So a big cheers!
 
Hi everyone,
While running Java-programs from the command console you must specify the entire package to the class.
For example:
if your class "MyJavaApp" resides in the package "Main/JavaApps" you must run the program through the command "java Main.JavaApps.MyJavaApp", and must be in the root-directory for the package Main.
Thus, if your .CLASS file is in the directory "D:\Java\Main\JavaApps\MyJavaApp.class" run the command from the directory "D:\Java".

Hope this helps!
 
Thanks.."elgreatfoxman". You read my mind!! I got stuff to compile and work and then wanted to get some apps working using packages, and your input answered all my questions. So a big thanks for that!!

However!! I have another issue related to this. I am trying to use SAX to Parse an XML document. I can compile the App and it runs and outputs stuff. But!! The SAX part of the application returns the following error,

Servlet SAX Exception: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

So I guess it is another class path issue!! My PC class path is set as follows,

%JAVA_HOME%\lib\*.jar;%J2EE_HOME%\lib\*.jar;c:\xerces-2_0_2\*.jar

where I have the xerces parser installed in (c:\xerces-2_0_2\).

Any ideas please!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top