My Personal Online Recycle Bin
You may find something useful here...........

Wednesday, December 21, 2005

NoClassDefFoundError.........

Today, I got a NoClassDefFoundError error message when I tried to execute a java program from command line with "java classname" in a linux environment.

I was so suprised because the class should be working perfectly fine. This is because this is a utility class that is used in a web application which is executed everyday. All the required class must be there. Else program should not run and the user should have complaint already.

I wonder may be I am in wrong working path. So I print the working directory and list the files under the path. Everything was fine. The path is correct and the class file is there. Then I triead again with "java classname". Miracle didn't happen, I get the same message.

After a few different fail attempt, I finally succesfully call the program with "java com.xxx.xxx.xxx.classname". Yes......I successfully call the program with a fully qualified class name. But I don't understand why do I need a fully qualified name to call the program since i am already in the same directory with the class????

After a serch on google, I found the following that give me some info on the error message.
There are two major types of class path problems. The first occurs when a Java class you are trying to use is not found in the class path, so it throws a java.lang.ClassNotFoundException exception. The second problem occurs when the class you are trying to use is found, but one of the classes it imports is not found. In this case, at compile time the imported classes were present, but at run time the imported class was not part of the class path. This will throw a java.lang.NoClassDefFoundError exception. Another way to think of the NoClassDefFoundError is to say that the searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found at runtime. Full article can be found here


Anyway, I still don't understand why I need to used a fully qualified name to call the class. May be some one can clarify my doubt.

0 Comments:

Post a Comment

<< Home