简体   繁体   English

Java class 未发现异常

[英]Java class not found exception

I'm trying to run a Java program and somewhere along the execution, I get a我正在尝试运行 Java 程序,在执行过程中,我得到了一个

java.lang.NoClassDefFoundError: antlr/TokenStream

exception.例外。 I'm new to java programming so don't really know what this means.我是 java 编程的新手,所以真的不知道这意味着什么。 I've looked through some other questions about the same issues and they didn't really help me out - either I couldn't follow the answer or it didn't apply in my case.我已经查看了有关相同问题的其他一些问题,但它们并没有真正帮助我——要么我无法遵循答案,要么它不适用于我的案例。 Any ideas?有任何想法吗?

search for antlr.jar and place it to your classpath搜索 antlr.jar 并将其放置到您的类路径中

java.lang.NoClassDefFoundError is thrown when a particular class referenced by your program is not available in the classpath.当您的程序引用的特定java.lang.NoClassDefFoundError在类路径中不可用时,将引发 java.lang.NoClassDefFoundError。 Classpath is the list of paths/directories that the runtime searches for the classes used in the class being run.类路径是运行时搜索正在运行的 class 中使用的类的路径/目录列表。

The error message you get means that antlr/TokenStream is not available in your classpath.您收到的错误消息意味着antlr/TokenStream在您的类路径中不可用。

To include the corresponding jar ( antlr.jar ) to the classpath, you ca use the -cp flag while running:要将相应的 jar ( antlr.jar ) 包含到类路径中,您可以在运行时使用-cp标志:

java -cp .;path_to_antlr.jar yourClass

Or或者

java -cp .;path_to_antlr.jar -jar yourJar.jar

It is searching for the defn of the class, which it is not finding in the classpath.它正在搜索 class 的定义,但在类路径中找不到。

From the JavaDoc's ,JavaDoc 中

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.如果 Java 虚拟机或 ClassLoader 实例尝试加载 class 的定义(作为正常方法调用的一部分或作为使用新表达式创建新实例的一部分)并且找不到 ZA2F2ED2AA2A4F8EBC2CBB4C21 的定义。

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.如果 Java 虚拟机或 ClassLoader 实例尝试加载 class 的定义(作为正常方法调用的一部分或作为使用新表达式创建新实例的一部分)并且找不到 ZA2F2ED2AA2A4F8EBC2CBB4C21 的定义。

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.搜索到的 class 定义在编译当前正在执行的 class 时存在,但无法再找到该定义。

Take from here .这里取。

You have made reference to a java class but for some reason, that class does not exist in the execution image you are running.您已经参考了 java class 但由于某种原因,您正在运行的执行映像中不存在 class 。 For example, if you instantiated a new class XYZ like: XYZ xyz = new XYZ (), but no such class existed you would get an error similar to the above.例如,如果您实例化了一个新的 class XYZ,例如:XYZ xyz = new XYZ (),但不存在这样的 class,您将收到与上述类似的错误。 In the past, I've received this kind of error if I misspelled a reference to a class or more typically, if the class to which I was referring somehow did not get included in my jar.过去,如果我拼错了对 class 或更常见的引用的引用,如果我所指的 class 以某种方式未包含在我的 Z68995FCBF432492D15484D04A9D2AC40 中,我会收到此类错误Check the jar or the directory in which you are doing the execution.检查 jar 或您正在执行的目录。 Do you see the class to which you are making reference there?你看到你在那里参考的 class 了吗? I bet it is missing.我敢打赌它不见了。

Elliott艾略特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM