Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

java - 为什么在Java中收到NoClassDefFoundError?(Why am I getting a NoClassDefFoundError in Java?)

I am getting a NoClassDefFoundError when I run my Java application.

(运行Java应用程序时出现NoClassDefFoundError 。)

What is typically the cause of this?

(通常是什么原因造成的?)

  ask by John Meagher translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.

(尽管这可能是由于编译时和运行时之间的类路径不匹配导致的,但不一定是正确的。)

It is important to keep two or three different exceptions straight in our head in this case:

(在这种情况下,请务必牢记两个或三个不同的异常:)

  1. java.lang.ClassNotFoundException This exception indicates that the class was not found on the classpath.

    (java.lang.ClassNotFoundException此异常表明在类路径上找不到该类。)

    This indicates that we were trying to load the class definition, and the class did not exist on the classpath.

    (这表明我们正在尝试加载类定义,并且该类在类路径中不存在。)

  2. java.lang.NoClassDefFoundError This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it.

    (java.lang.NoClassDefFoundError此异常表明JVM在其内部类定义数据结构中查找了类的定义,但未找到。)

    This is different than saying that it could not be loaded from the classpath.

    (这与说无法从类路径中加载不同。)

    Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again).

    (通常,这表明我们以前曾尝试从类路径中加载类,但由于某种原因而失败-现在我们正尝试再次使用该类(因此,由于上次失败,因此需要对其进行加载),但是我们甚至不打算尝试加载它,因为我们无法提前加载它(并且合理地怀疑我们会再次失败)。)

    The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems.

    (较早的故障可能是ClassNotFoundException或ExceptionInInitializerError(指示静态初始化块中的故障)或许多其他问题。)

    The point is, a NoClassDefFoundError is not necessarily a classpath problem.

    (关键是,NoClassDefFoundError不一定是类路径问题。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...