简体   繁体   中英

why is my `getClass().getResource(“logs”)` returns null?

I have this code:

this.fileName = getClass().getResource("logs").toURI().toString();

which fails for null pointer exception because getClass().getResource("logs") returns null

what am I missing?

在此处输入图片说明

You're looking for a resource which is relative to the LogUtils class.

You could use getClass().getResource("/logs") or you could use getClass().getClassLoader().getResource("logs") .

(In either case, I'm not 100% convinced it'll work when that's a folder rather than an actual resource...)

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