Non of the java programs which used to run fine in my computer has stopped running. There are no errors in da programs as they still run fine in other computers. All programs gives the folllowing error "Exception in thread "main" java.lang.NoClassDefFoundError"

I set my classpath and the path fine they are set as following :
CLASSPATH := C:\WINDOWS\System32\QTJava.zip\C:\j2sdk1.4.0\bin\;%CLASSPATH%;
path := PATH = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\j2sdk1.4.0\bin

can some body please help me !!

Dani AI

Generated

Quick summary and practical checks for "Exception in thread 'main' java.lang.NoClassDefFoundError": this Error means the JVM tried to load a class at runtime but could not find its definition (the class existed at compile time). It is distinct from a ClassNotFoundException, which is a checked exception thrown when code explicitly asks a classloader for a class by name. See Oracle’s API notes for NoClassDefFoundError and ClassNotFoundException. (docs.oracle.com)

Steps to diagnose and fix (do these in order):

  • Run the program from the directory that is the root of your package tree and launch the fully qualified main class. For small tests prefer passing the classpath on the command line rather than relying on a system CLASSPATH.
java -cp . com.example.Main
  • Verify the .class files are in folders that match their package declarations (package a.b.c -> a/b/c/Main.class).
  • If you use JARs, inspect them with jar tf mylib.jar and confirm entries use the expected package paths.
  • Prefer -classpath/-cp for application-specific settings; setting a global CLASSPATH replaces the default (current directory). (docs.oracle.com)

Windows gotchas and tools.jar note:

  • On Windows classpath entries are separated with a semicolon (;); forgetting or mis-typing separators corrupts the classpath. Also, if you overwrite CLASSPATH you must explicitly include . to keep the current directory in the search path.
  • Do not put the JDK bin directory on the classpath — bin contains executables (put it on PATH instead). tools.jar lives under the JDK lib and contains tool/compiler classes; it is not normally required to run an application unless a tool explicitly needs it. (docs.oracle.com)

Quick debugging helpers and best practice:

  • Run java -verbose:class -cp . com.example.Main to see what classes the JVM actually loads and where it looks. Use per-app -cp scripts or your IDE/build tool to manage dependencies instead of a global CLASSPATH. (docs.oracle.com)

As spotted, separators matter; as noted, be sure the current directory is visible to the JVM; raised the tools.jar point (use it only if a tool needs it); and congrats to for getting the program running.

Recommended Answers

All 8 Replies

Your classpath is wrong. It should point to the tools.jar file in your jdk directory. When you do this MAKE SURE that you add a period to the end of tools.jar like so:

tools.jar.

tools.jar doesn't need to be (in fact shouldn't be) on the classpath.

What is missing from the classpath is the current directory ('.'). On older machines running Windows 9x that's no problem, on NT based and Unix based operating systems it's required.

tools.jar doesn't need to be (in fact shouldn't be) on the classpath.

Really? I've never been tought different, nor known different...Could you explain?

tools.jar is used internally by the JVM (like rt.jar). It knows where to find it as it knows where to find itself.

But what should the classpath be pointing to then?

to the current directory (.) and any OPTIONAL libraries (so anything not included in the JVM installation itself).

There is an error in the classpath you have specified. You have a '\' after QTJava.zip, you need a ';' (semi colon) there.

Like this:

C:\WINDOWS\System32\QTJava.zip;C:\j2sdk1.4.0\bin\;%CLASSPATH%;

thnak u every body for all ur support and time for analysiing my problem. and i am really happy to say the class path specified as :
C:\WINDOWS\System32\QTJava.zip;C:\j2sdk1.4.0\bin\;%CLASSPATH%;
came out to be a success. and i send a special thank to kate.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.