title: getClass().getResource() in static context
body: <p>I'm trying to get a resource (image.png, in the same package as this code) from a static method using this code:</p>
  
  <pre><code>import java.net.*;
  
  public class StaticResource {
  
      public static void main(String[] args) {
          URL u = StaticResource.class.getClass().getResource("image.png");
          System.out.println(u);
      }
  
  }
  </code></pre>
  
  <p>The output is just 'null'</p>
  
  <p>I've also tried <code>StaticResource.class.getClass().getClassLoader().getResource("image.png");</code>
  , it throws a <code>NullPointerException</code></p>
  
  <p>I've seen other solutions where this works, what am I doing wrong?</p>