Search code examples
javanetbeansgetresource

java netbeans getClass().getResource(filename) return null


I have a picture resource in my netbeans project and the getResource(...) method returns null, for every combination. Can you see what I am doing wrong from this screenshot?

Netbeans screen shot


Solution

  • getClass() returns TreeTestController.class (assuming the method is not called on a subclass), which is in the package javafxaddress.view. getResource() uses a path that is relative to the package of the class on which it is called, unless the path starts with /. So your code looks for the file in the package javafxaddress.view.media, and the file is in fact in the package javafxaddress.media.

    So the path should be /javafxaddress/media/1414459175_Save.png.