简体   繁体   English

getClass()。getClassLoader()。getResourceAsStream引发NullPointerException

[英]getClass().getClassLoader().getResourceAsStream is throwing a NullPointerException

In Java How could getClass().getClassLoader() return null? 在Java中,getClass()。getClassLoader()如何返回null?

  • The jar the 'class' is located in is NOT located under common/lib. “类”所在的jar不在common / lib下。
  • The jar is NOT being boostrap-loaded. 罐子没有被加载。

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.

相关问题 java jar getClass().getClassLoader().getResourceAsStream 返回空指针异常 - java jar getClass().getClassLoader().getResourceAsStream return nullpointerexception getClass()。getClassLoader()。getResourceAsStream()正在缓存资源 - getClass().getClassLoader().getResourceAsStream() is caching the resource Java OutputStream 等价于 getClass().getClassLoader().getResourceAsStream() - Java OutputStream equivalent to getClass().getClassLoader().getResourceAsStream() this.getClass()。getClassLoader()。getResourceAsStream始终返回null - this.getClass().getClassLoader().getResourceAsStream always returning null this.getClass()。getClassLoader()。getResourceAsStream()在RCP产品中不起作用 - this.getClass().getClassLoader().getResourceAsStream()is not working in RCP product getClass().getClassLoader().getResourceAsStream() 总是返回 null,资源在 application.jar 中 - getClass().getClassLoader().getResourceAsStream() always returns null, resource is in application.jar 如何将getClass.getClassLoader()。getResourceAsStream()值传递给FileOutputStream - How to pass getClass.getClassLoader().getResourceAsStream() value to FileOutputStream getClassLoader()。getResource()抛出NullPointerException?为什么不FileNotFoundException? - getClassLoader().getResource() throwing NullPointerException? Why not FileNotFoundException? 为什么 getClass().getResourceAsStream(file.getAbsolutePath()) 会抛出 nullPointerException? - Why getClass().getResourceAsStream(file.getAbsolutePath()) throws nullPointerException? Java getClassLoader()。getResourceAsStream(文件名) - Java getClassLoader().getResourceAsStream(filename)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM