编程语言
首页 > 编程语言> > Java Reflections’NoClassDef’错误

Java Reflections’NoClassDef’错误

作者:互联网

我正在尝试浏览所有使用自定义库反射实现了接口的类.这是我的资料来源:

public static List<IModdable> getAllModClasses() {
    Reflections reflections = new Reflections("mod.api.core"); //getting error here
    Set<Class<? extends IModdable>> classes = reflections.getSubTypesOf(IModdable.class);
    List<IModdable> modList = new ArrayList<IModdable>();
    for (Class<? extends IModdable> c : classes)
        try {
            modList.add((IModdable) c.newInstance());
        } catch (Exception ex) {
            err(String.format("Could not load mod %s !", c.getName()));
        }


    return modList;
}

错误:

Exception in thread "Client thread" java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
    at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100)
    at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24)
    at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30)
    at org.reflections.Reflections.scan(Reflections.java:238)
    at org.reflections.Reflections.scan(Reflections.java:204)
    at org.reflections.Reflections.<init>(Reflections.java:129)
    at org.reflections.Reflections.<init>(Reflections.java:170)
    at org.reflections.Reflections.<init>(Reflections.java:143)
    at mod.api.core.CoreProvider.getAllModClasses(CoreProvider.java:17)
    at mod.api.core.ModCore.onLoad(ModCore.java:13)
    at net.minecraft.client.Minecraft.run(Minecraft.java:405)
    at net.minecraft.client.main.Main.main(Main.java:114)
    at Start.main(Start.java:11)
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 13 more

mod.api.core包退出.所以那不应该是错误.

解决方法:

java.lang.NoClassDefFoundError:javassist / bytecode / ClassFile

您可以通过将javassist-3.12.1.GA.jar添加到类路径来解决此问题

标签:reflection,runtime-error,java
来源: https://codeday.me/bug/20191028/1950683.html