简体   繁体   中英

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);

Why? when getResourceAsStream() can't find the file, it would return null, but won't throw a NullPointerException right?

I'm using Eclipse and I just drag the jar package into my project linked it in the properties. Did I miss something?

I want to know why and how to fix that?

Thinks

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM