How to add .png to classpath

Answered

I've been reading around in several different posts and I'm unsure if any of them are specific enough for my issue. I have a png that I'm trying to load in as an Input Stream file. By this line of code: 

InputStream file = ClassLoader.class.getResourceAsStream("resources/chart.png");

From what I understand the png needs to be in the classpath. unfortunately all my attempts have failed. I have added the png path to the module dependencies as a class. I have added ?*.png to the compiler's Resource Patterns, and I have "java" and "resources" as Source folders for the Module.
Whenever I return the classpath I still don't see the png in it, or the resources folder it's under. I'm assuming that is why the function getResourceAsStream() is returning null.

Let me know if you need more info.
Thanks,

0
2 comments

The directory above resources must be marked as resource root or if the resources directory is marked as the root, you need to change the path to just /chart.png.

0
Avatar
Permanently deleted user

There it is, I was missing the slash. I originally have been putting "chart.png" previously. It's amazing how much time can be wasted on a little syntax error. Спасибо Большое))

0

Please sign in to leave a comment.