title: JavaFX loading CSS style from resources folder
body: <p>Project Structure:</p>
  
  <p><a href="https://i.stack.imgur.com/QVKPA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QVKPA.png" alt="Project Structure"></a></p>
  
  <p>I'm currently developing a JavaFX application in Eclipse and I'm having trouble loading a .css stylesheet from the resources folder. </p>
  
  <p>I've already added the resources folder to the classpath (<strong>Project Properties</strong> -> <strong>Source</strong> -> <strong>Add Folder</strong>)</p>
  
  <p>The following code is being used:</p>
  
  <pre class="lang-java prettyprint-override"><code>this.getStylesheets().add(getClass().getResource("/CSS/application-container.css").toExternalForm());
  </code></pre>
  
  <p><code>getResource()</code> is throwing <strong>NullPointerException</strong> I've read other posts and tried everything but can't seem to get it to work.</p>
  
  <p><strong>EDIT:</strong> Managed to get it working by deleting and restoring the bin folder. Now the .css is loaded but by some reason it's not being applied, however using the javaFX method <code>.setStyle(...)</code> with the same content of the .css, it works.</p>
  
  <pre><code>private void buildHeader() {
      this.header.setId("header-container");
      this.getStylesheets().add(getClass().getResource("/CSS/application-container.css").toExternalForm());
      // this.header.setStyle("-fx-background-color: #7b9bce;");      this way works
  }
  </code></pre>
  
  <p>CSS:</p>
  
  <pre><code>@charset"utf-8";
  
  #header-container {
      -fx-background-color: #7b9bce;
  }
  </code></pre>