[英]getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException
In Java How could getClass().getClassLoader() return null? 在Java中,getClass()。getClassLoader()如何返回null?
The ClassLoader for all classes within the jar is null. jar中所有类的ClassLoader为null。
From the documentation ... 从文档中 ...
public ClassLoader getClassLoader()
Returns the class loader for the class. 返回该类的类加载器。 Some implementations may use null to represent the bootstrap class loader. 一些实现可能使用null来表示引导类加载器。 This method will return null in such implementations if this class was loaded by the bootstrap class loader. 如果此类是由bootstrap类加载器加载的,则此方法在此类实现中将返回null。
... ...
If this object represents a primitive type or void, null is returned. 如果此对象表示原始类型或void,则返回null。
Are you using any endorsed standards ? 您是否使用任何认可的标准 ? I believe this would cause the classes to be loaded by the bootstrap class loader even though you may not be explicitly using -Xbootclasspath. 我相信这将导致引导类加载器加载类,即使您可能未明确使用-Xbootclasspath。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.