GetResourceAsStream returns null

I have seen many other people ask this question here and here , but it seems that I have done everything I need, but I still get null when using the getResourceAsStream () call.

In netbeans, I dragged my image into my package and it appears in the folder where the source code and .class files are stored. So what am I: CIC \ com \ MyProject \ ClassIMakeTheCallFrom.java CIC \ com \ MyProject \ MyImage.png

a similar structure exists in: build \ classes \ com \ MyProject \ ClassIMakeTheCallFrom.class build \ classes \ com \ MyProject \ MyImage.png

However, when I make a call:

System.out.println(dolphinWater.class.getClassLoader().getResourceAsStream("myImage.png")); 

It turns out null. Did I miss something?

+2
java jnlp netbeans
Aug 10 '11 at 20:28
source share
1 answer

Place the file directly in the src folder, not in the package folder. Or use getResourceAsStream("com/myProject/myImage.png") .

http://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)

+3
Aug 10 '11 at 20:52
source share



All Articles