title: Can't Access File in Resources Folder
body: <p>I'm trying to load an image that I have stored in my /src/main/resources folder. When I do, however, I keep running into a NullPointerException that stems from the resource not being found.</p>
  
  <p>Here is the code snippet: </p>
  
  <pre><code>        try {
              String path = this.getClass().getClassLoader().getResource("bern.png").toString();
          } catch (IOException ex) {
              System.out.println(path);
          }
  </code></pre>
  
  <p>Here is an image of my project file tree: </p>
  
  <p><a href="https://i.stack.imgur.com/D0U5x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D0U5x.png" alt="An image of my project file tree"></a></p>
  
  <p>And here is an image of my target build file tree: </p>
  
  <p><a href="https://i.stack.imgur.com/3mmuo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3mmuo.png" alt="An image of my target build file tree"></a></p>
  
  <p>Here is the NullPointerException stacktrace: 
  <a href="https://pastebin.com/KqJVxWEL" rel="nofollow noreferrer">https://pastebin.com/KqJVxWEL</a></p>
  
  <p>I have tried using pretty well every possible path for the image file that I can think of. (/src/main/resources/bern.png, src/main/resources/bern.png, /bern.png, etc.).</p>
  
  <p>I have also tried using <code>getClass().getClassLoader().getResource()</code> instead of <code>getClass().getResource()</code>. From what I understand, the only difference between the <code>Class</code> and <code>ClassLoader</code> version of <code>getResource()</code> is that the <code>Class</code> version is not inherently absolute relative to the root, whereas the <code>ClassLoader</code> version is. </p>
  
  <p>When I run <code>getClass().getResource("").toPath()</code>, I get the path that leads to the <code>classes</code> directory. This aligns with what I've read about the <code>getResource()</code> method working with the target build file tree. However, I don't see the resources folder showing up anywhere in the target build; I think that's the core of my problem. I'm just not sure how to fix it. </p>
  
  <p>I know this question has been asked numerous times before, but the answers to the other version of this question haven't helped me out much. </p>
  
  <p>I'm using NetBeans 11, and this project is running on the Maven build system. I haven't done much work with Maven in the past, so forgive me if this problem is extremely easy to fix. </p>
  
  <p>Anyone know how I'm approaching this wrong? </p>
  
  <p>EDIT: The problem is not anything with my project structure or code as shown by the code compiling correctly when run using <code>mvn</code> via the command line. As a result, it's an issue with NetBeans specifically and the way that it is viewing the resources folder. </p>