开发者

Java class not found exception

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 abo开发者_如何学Cut 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


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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜