接口(不是类)上的NoClassDefFoundError [英] NoClassDefFoundError on an interface, not a class

查看:104
本文介绍了接口(不是类)上的NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NoClassDefFoundError上遇到问题.我正在使用接口,并且没有可用的类定义:

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

package code;
public interface Constants {...}

实现此接口的类编译无任何错误,并且已经构建了JAR文件,但是在运行时它给我一个错误.

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仅包含常量列表.

我阅读了一些指向CLASSPATH的帖子,这是导致此问题的原因,但是我的CLASSPATH中有code软件包.如果我没有它,它将产生一个编译错误.因此,问题应该出在其他地方.

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.

运行时错误为:

java.lang.NoClassDefFoundError: code/Constants

有什么解决方案?

推荐答案

检查此类的静态初始化.请看这里: NoClassDefFoundError和ClassNotFoundException之间有什么区别.
java.lang.NoClassDefFoundError: code/Constants并不意味着Constants类不在CLASSPATH中.实际上,情况恰恰相反.这意味着该类是由ClassLoader找到的,但是在尝试加载该类时,它在读取类定义时遇到了错误.通常,当所涉及的类具有使用ClassLoader找不到的类的静态块或成员时,就会发生这种情况.

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.

这篇关于接口(不是类)上的NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆