Elad Benda2
Elad Benda2

Reputation: 15442

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

Upvotes: 1

Views: 723

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499860

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

Upvotes: 2

Related Questions