Luchian Grigore
Luchian Grigore

Reputation: 258548

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 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?

Upvotes: 3

Views: 12965

Answers (5)

Elliott
Elliott

Reputation: 5609

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

Upvotes: 0

Nivas
Nivas

Reputation: 18344

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

Upvotes: 2

Shamim Hafiz - MSFT
Shamim Hafiz - MSFT

Reputation: 22064

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.

Upvotes: 0

Saurabh Gokhale
Saurabh Gokhale

Reputation: 46395

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.

Upvotes: 0

fmucar
fmucar

Reputation: 14548

search for antlr.jar and place it to your classpath

Upvotes: 5

Related Questions