Java类未找到异常

发布于 2024-11-29 05:34:56 字数 215 浏览 3 评论 0原文

我正在尝试运行一个 Java 程序,在执行过程中的某个地方,我遇到了

java.lang.NoClassDefFoundError: antlr/TokenStream

异常。我是java编程新手,所以不太清楚这意味着什么。我查看了有关相同问题的其他一些问题,但它们并没有真正帮助我 - 要么我无法遵循答案,要么它不适用于我的情况。 有什么想法吗?

I'm trying to run a Java program and somewhere along the execution, I get a

java.lang.NoClassDefFoundError: antlr/TokenStream

exception. I'm new to java programming so don't really know what this means. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

十六岁半 2024-12-06 05:34:56

搜索 antlr.jar 并将其放置到您的类路径中

search for antlr.jar and place it to your classpath

神回复 2024-12-06 05:34:56

当程序引用的特定类在类路径中不可用时,会抛出 java.lang.NoClassDefFoundError 。类路径是运行时搜索正在运行的类中使用的类的路径/目录列表。

您收到的错误消息意味着 antlr/TokenStream 在您的类路径中不可用。

要将相应的 jar (antlr.jar) 包含到类路径中,您可以在运行时使用 -cp 标志:

java -cp .;path_to_antlr.jar yourClass

或者

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

java.lang.NoClassDefFoundError is thrown when a particular class referenced by your program is not available in the classpath. Classpath is the list of paths/directories that the runtime searches for the classes used in the class being run.

The error message you get means that antlr/TokenStream is not available in your classpath.

To include the corresponding jar (antlr.jar) to the classpath, you ca use the -cp flag while running:

java -cp .;path_to_antlr.jar yourClass

Or

java -cp .;path_to_antlr.jar -jar yourJar.jar
笑梦风尘 2024-12-06 05:34:56

它正在搜索类的定义,但在类路径中找不到。

来自 JavaDoc 的

如果 Java 虚拟机或类加载器实例尝试
加载类的定义(作为正常方法调用的一部分或
作为使用 new 表达式创建新实例的一部分)并且没有
可以找到类的定义。

It is searching for the defn of the class, which it is not finding in the classpath.

From the JavaDoc's,

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.

层林尽染 2024-12-06 05:34:56

如果 Java 虚拟机或类加载器实例尝试
加载类的定义(作为正常方法调用的一部分或
作为使用 new 表达式创建新实例的一部分)并且没有
可以找到类的定义。

当前执行时搜索到的类定义已存在
类已编译,但无法再找到定义。

取自此处

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.

Take from here.

ペ泪落弦音 2024-12-06 05:34:56

您引用了一个 java 类,但由于某种原因,该类不存在于您正在运行的执行映像中。例如,如果您实例化了一个新类 XYZ,如下所示:
XYZ xyz = new XYZ(),但是不存在这样的类,你会得到类似上面的错误。在过去,如果我错误地拼写了对类的引用,或者更典型的是,如果我所引用的类以某种方式没有包含在我的 jar 中,我就会收到这种错误。检查 jar 或执行执行的目录。您看到您在那里引用的课程了吗?我敢打赌它不见了。

埃利奥特

You have made reference to a java class but for some reason, that class does not exist in the execution image you are running. 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. 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. Check the jar or the directory in which you are doing the execution. Do you see the class to which you are making reference there? I bet it is missing.

Elliott

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文