简体   繁体   English

使用class.getClassLoader()。getResourceAsStream时抛出java.lang.NullPointerException

[英]java.lang.NullPointerException throws while using class.getClassLoader().getResourceAsStream

When I'm using an referenced library, The NullPointerException have been thrown, it caused by: InputStream inputStream = VersionInfoUtils.class.getClassLoader().getResourceAsStream(VERSION_INFO_FILE); 当我使用引用的库时,抛出了NullPointerException,它是由以下原因引起的: InputStream inputStream = VersionInfoUtils.class.getClassLoader().getResourceAsStream(VERSION_INFO_FILE);

Why? 为什么? when getResourceAsStream() can't find the file, it would return null, but won't throw a NullPointerException right? getResourceAsStream()找不到文件时,它将返回null,但是不会抛出NullPointerException吗?

I'm using Eclipse and I just drag the jar package into my project linked it in the properties. 我正在使用Eclipse,我只是将jar包拖到我的项目中,并将其链接到属性中。 Did I miss something? 我错过了什么?

I want to know why and how to fix that? 我想知道为什么以及如何解决?

Thinks 认为

我发现Class.getClassLoader()在某些特定情况下可以返回null,因此发生NullpointerException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 class.getClassLoader getResourceasStream在jar中返回null - class.getClassLoader getResourceasStream returns null in jar install4j6:class.getClassLoader()。getResourceAsStream(fileName)返回Null - install4j6: class.getClassLoader().getResourceAsStream(fileName) returns Null 使用POI引发java.lang.NullPointerException - Using POI throws java.lang.NullPointerException Java:无法弄清楚如何使用class.getClassLoader()。getResourceAsStream(),因此在构建工件时可以使用 - Java: Can't figure out how to use class.getClassLoader().getResourceAsStream() so it works when i build artifacts 使用 Actions 类时的 java.lang.NullPointerException - java.lang.NullPointerException while using Actions Class java.lang.NullPointerException:使用Firebase时 - java.lang.NullPointerException: while using firebase 使用ServletContext时java.lang.NullPointerException - java.lang.NullPointerException while using ServletContext java jar getClass().getClassLoader().getResourceAsStream 返回空指针异常 - java jar getClass().getClassLoader().getResourceAsStream return nullpointerexception 使用构造函数将变量放入对象会抛出 java.lang.NullPointerException - Using a constructor to put variables into an object throws java.lang.NullPointerException TestNG抛出“ java.lang.NullPointerException” - TestNG throws “java.lang.NullPointerException”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM