title: @FXML controller components are null after initialize
body: <p>I have looked at <a href="https://stackoverflow.com/questions/17634591/javafx-fxml-is-null-outside-initialize">this</a>, <a href="https://stackoverflow.com/questions/34320276/fxml-objects-are-null-in-initialize-method">this</a> and <a href="https://stackoverflow.com/questions/22910611/javafx-controller-is-always-null">this</a> but sadly there is not a single one that resolves my problem. The components are always null. The ids are the same but I still don't know what I am doing wrong. Below is my code : </p>
  
  <p>Application Class.</p>
  
  <pre><code>public class Main extends Application {
  @Override
  public void start(Stage primaryStage) throws Exception {
      Parent root = FXMLLoader.load(LocalFileUtils.getResourceAsURL("RootView.fxml"));
      primaryStage.setScene(new Scene(root));
      primaryStage.show();
  
  }
  
  public static void main(String[] args) {
      launch(args);
  }
  }
  </code></pre>
  
  <p>RootView.fxml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import java.lang.*?&gt;
  &lt;?import javafx.scene.layout.*?&gt;
  &lt;?import javafx.scene.shape.*?&gt;
  &lt;?import javafx.scene.control.*?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.layout.ColumnConstraints?&gt;
  &lt;?import javafx.scene.layout.RowConstraints?&gt;
  
  &lt;BorderPane id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="main.MainViewController"&gt;
     &lt;center&gt;
        &lt;AnchorPane id="mainAnchorPane" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" /&gt;
     &lt;/center&gt;
  &lt;/BorderPane&gt;
  </code></pre>
  
  <p>Controller Class</p>
  
  <pre><code>    package main;
  
  import java.net.URL;
  import java.util.ResourceBundle;
  
  import javafx.fxml.FXML;
  import javafx.fxml.Initializable;
  import javafx.scene.layout.AnchorPane;
  
  public class MainViewController implements Initializable {
      @FXML
      private AnchorPane mainAnchorPane;
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          // TODO Auto-generated method stub
          System.out.println("Started");
          System.out.println(location); // Prints out he URL of the RootView
          System.out.println(resources); //Always Null
          System.out.println(mainAnchorPane); //Always Null
      }
  
  }
  </code></pre>
  
  <p>The App runs okay. Have I missed something?</p>