开发者

ClassDefNotFoundException [closed]

开发者 https://www.devze.com 2023-01-17 01:33 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_StackOverflow Closed 12 years ago.

What is ClassDefNotFoundException and NoClassDefFoundError and explain differences between these two?


Typically, NoClassDefFoundError is thrown if the class failed to initialize.

When a class is used for the 1st time, it's being initialized. if that fails for whatever reason, the relevant exception is thrown. http://java.sun.com/docs/books/jls/third_edition/html/execution.html#12.4

When the class is used again, it's known to be corrupt. Initialization won't be attempted again. JVM throws the mysterious NoClassDefFoundError. Not really descriptive of the problem, could be quite confusing for diagnosis. It would be better if something like ClassInitFailedError is thrown.

When you see a NoClassDefFoundError, you should search the log backwards, find the root cause why the class failed to initialize (hopefully it's logged)


There is no ClassDefNotFoundException in standard Java lib, so I don't know what you are talking about.


ClassNotFoundException is thrown when the class cannot be found in the classpath. NoClassDefFoundError happens when class cannot be instantiated by new because the jvm failed to initialize the class. It could be the constructor threw exceptions, or static block threw up, or version mismatch.


Core Java - What is ClassDefNotFoundException and ...

http://www.geekinterview.com/question_details/47825

0

精彩评论

暂无评论...
验证码 换一张
取 消