Java类未找到异常
我正在尝试运行一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
搜索 antlr.jar 并将其放置到您的类路径中
search for antlr.jar and place it to your classpath
当程序引用的特定类在类路径中不可用时,会抛出 java.lang.NoClassDefFoundError 。类路径是运行时搜索正在运行的类中使用的类的路径/目录列表。
您收到的错误消息意味着
antlr/TokenStream
在您的类路径中不可用。要将相应的 jar (
antlr.jar
) 包含到类路径中,您可以在运行时使用-cp
标志:或者
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:Or
它正在搜索类的定义,但在类路径中找不到。
来自 JavaDoc 的,
It is searching for the defn of the class, which it is not finding in the classpath.
From the JavaDoc's,
取自此处 。
Take from here.
您引用了一个 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