[英]ClassLoader does not load inner class
ClassLoader
clMain -> URLClassLoader
clA (class A, $B). ClassLoader
clMain -> URLClassLoader
clA(A 类,$B)。 $B is a inner class B of the class A. $B 是 A 类的内部 B 类。
ClassLoader
, execute a method of the object A via interface without problems.另一个类,从 X ClassLoader
,通过接口执行对象 A 的方法没有问题。NoClassDefFoundError
.然后,在该方法中,应该创建新对象 $B,但它抛出NoClassDefFoundError
。this.getClass().getClassLoader().loadClass("A$B");
在类 A 的构造函数中加载类 $B 正在解决问题: this.getClass().getClassLoader().loadClass("A$B");
So, the cuestion is: "Why the definition of the class $B cannot be found for step 3 and Can be solved this porblem in another way?"所以,提示是: “为什么第 3 步找不到类 $B 的定义,并且可以用另一种方式解决这个问题?”
Checking the ClassLoader
used in the method ( this.getClass().getClassLoader()
) and comparing it with the ClassLoader
used in the constructor - is the same and contains the necessary url.检查方法中使用的ClassLoader
( this.getClass().getClassLoader()
) 并将其与构造函数中使用的ClassLoader
进行比较 - 是相同的,并包含必要的 url。 Java 8 and 14 tried to run, jdk 8 to build. Java 8 和 14 尝试运行,jdk 8 构建。
NoClassDefFoundError invariably means the $inner class file (in this specific case) itself could not be found . NoClassDefFoundError 总是意味着找不到$inner类文件(在这种特定情况下)本身。 packaging or copying problem or a url referencing problem (? JNDI naming problem) but whatever, the file was not located where stated.打包或复制问题或 url 引用问题(?JNDI 命名问题)但无论如何,该文件未位于声明的位置。 (sometimes the filename is a typo somewhere and the location to it is correct). (有时文件名是某个地方的拼写错误,它的位置是正确的)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.