title: Java getClass().getResource("file") leads to NullPointerException
body: <p>I am following the <a href="https://zetcode.com/javagames/snake/" rel="nofollow noreferrer">Snake Java games tutorial</a> and always get this error:</p>
  <pre><code>ImageIcon iid = new ImageIcon(this.getClass().getResource(&quot;ball.png&quot;));
  ball = iid.getImage();
  
  Exception in thread &quot;main&quot; java.lang.NullPointerException
      at javax.swing.ImageIcon.&lt;init&gt;(Unknown Source)
      at snake2.Board.&lt;init&gt;(Board.java:52)
      at snake2.Snake.&lt;init&gt;(Snake.java:10)
      at snake2.Snake.main(Snake.java:22)
  </code></pre>
  <p>I actually just copied and pasted the code to see how it works. They are in the right packages too; but when I try to run it, I always end up with this error.</p>