2

我正在尝试从文件夹加载类文件,以便用户可以与我的程序进行交互。用户应该能够扩展我创建的抽象类并将其放入文件夹中,但是每当我尝试加载一个类(我创建的,所以我知道它是正确的)时,它都会给我一个 InstantiationException。这是堆栈跟踪片段和发生错误的片段

[9:09:22 PM] Jav:         23:03:40 [SEVERE] java.lang.InstantiationException: UchihaClan
23:03:40 [SEVERE]       at java.lang.Class.newInstance0(Unknown Source)
23:03:40 [SEVERE]       at java.lang.Class.newInstance(Unknown Source)
23:03:40 [SEVERE]       at com.zavcoding.narutorpg.Classes.ClassLoader.load(ClassLoader.java:52)
23:03:40 [SEVERE]       at com.zavcoding.narutorpg.NarutoRPG.onEnable(NarutoRPG.java:38)



Class<?> clazz = loader.loadClass(name);
Object object = clazz.newInstance();
if (!(object instanceof UserMadeClass)) {
    System.out.println("Not a valid user class.");
    continue;
}
UserMadeClass umc = (UserMadeClass) object;
4

0 回答 0