title: Unable to access resources outside the package in Java
body: <p>I am currently developing a game, and have encountered a very burdensome problem.</p>
  
  <p>I want to draw a picture on the screen but every time I try to read the resource / picture I get NULL. I tried 2 kinds of methods to read the picture but still couldn't.</p>
  
  <p>But when I moved the image into the package that contains the class from which I was trying to read the image the image appeared.</p>
  
  <p>So the problem is that i just can't access resources outside of the current package. And i need to know how can i do that, how can i access this resource. It has to be a resource that I can use even after exporting the game to a JAR file.</p>
  
  <p><a href="https://i.stack.imgur.com/16GEa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/16GEa.png" alt="My Project Structure"></a></p>
  
  <p>Code I tried (The first one is buffered image and the second is just image type:</p>
  
  <pre><code>    try {
          image = ImageIO.read(getClass().getResource("blocks.png"));
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      --------------------------------------------------------------
  
      image = new ImageIcon(getClass().getResource("blocks.png))).getImage();
  </code></pre>
  
  <p>I hope the question is clear enough.</p>