Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
462 views
in Technique[技术] by (71.8m points)

java - NoClassDefFoundError on an interface, not a class

I have an issue with NoClassDefFoundError. I am using interfaces, and no class definition should be available:

package code;
public interface Constants {...}

The class implementing this interface compiles without any errors, and a JAR file has been built, but at runtime it gives me an error.

import ...;
import code.*;
public class MultiDoc extends LanguageAnalyser implements Constants{}

Constants contains only a list of constants.

I read some posts pointing to CLASSPATH as a cause of this problem, but I have the code package in my CLASSPATH. If I didn't have it, it would produce a compilation error. So, the problem should be something else.

The runtime error is:

java.lang.NoClassDefFoundError: code/Constants

What's the solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Check the static initialization of this class. Look here: what is the difference between NoClassDefFoundError and ClassNotFoundException.
java.lang.NoClassDefFoundError: code/Constants does not mean that the Constants class is not in the CLASSPATH. In fact it is quite the opposite. It means that the class was found by the ClassLoader, however when trying to load the class, it ran into an error reading the class definition. This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...