wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes No ClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "No ClassDefFoundError" Watch "No ClassDefFoundError" New topic

No ClassDefFoundError

JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303

i have a program in IO with a main method. I am trying to run the program thru the console. however, it gives me java.lang.NoClassDefFoundError.

I have configured java home, the bin and the lib folders. also added the working folder to the classpath. i also tried to go into the directory containing the .class file and run the same with the java command. However, i get the same error.

wht am i missing?

SCJP 1.4, SCWCD 1.4<br /> <br />Thanks in advance!<br />Jayashree.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312

public class NoClassDefFoundError
extends LinkageError

Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

Java Developer, Thailand
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
If you post the error message you receive we might be able to help, but there is definately something wrong in the way you are trying to access a class.
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Is the class public?
JayaSiji Gopal
Ranch Hand

Joined: Sep 27, 2004
Posts: 303
Originally posted by somkiat puisungnoen:

This is the text of the error message that i receive

C:\Jayashree\Examples\printHTML\classes\test\print>java printHTML
Exception in thread "main" java.lang.NoClassDefFoundError: printHTML (wrong name
: test/print/printHTML)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Pitchaimani Raju

Joined: Sep 08, 2004
Posts: 1
hi Gopal ,
i think so, your class printHTML is under package test.print. you have to run your class from C:\Jayashree\Examples\printHTML\classes folder and you have to give the following command java test.print.printHTML. now it will work properly.



Regards<br />Pitchaimani Raju
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Please post your code to solve this problem.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Vedhas Pitkar:
Is the class public?

I think, public Class name in source code is not "printHTML".
Ashish Vegaraju
Ranch Hand

Joined: Aug 19, 2004
Posts: 47

this error generally comes if ur classpath is not set correctly...do the following..

open command prompt and write this command

set CLASSPATH=%CLASSPATH%C:\j2sdk1.bla...bla...version\bin;.(semicolon followed by full stop[THIS IS IMP])

try this...if it doesnt help..let me know
It is sorta covered in the JavaRanch Style Guide.
subject: No ClassDefFoundError
Similar Threads
Why does my java program only run with -debug in my parameters
Any user of instantDB??
Java Runtime problem from DOS Prompt(Urgent!)
Unable to get/download a jar/zip file using ant script
main method synchronization