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?

enter image description here

Jon Skeet
people
quotationmark

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

people

See more on this question at Stackoverflow