title: JavaFX fxml loader does not work properly
body: <p>testFX.java :</p>
  
  <pre><code>public class testFX extends Application {
      @Override
      public void start(Stage primaryStage) throws Exception {
          try{
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(getClass().getResource("/testFX/view/test.fxml"));
              System.out.println("after set location");
              //PROBLEM
              AnchorPane root = (AnchorPane)loader.load();
              System.out.println("Does not happen");
              testFXController listController = loader.getController();
              listController.start();
              Scene scene = new Scene(root, 200, 300);
              scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
              primaryStage.setScene(scene);
              primaryStage.show();
          }
          catch (Exception ex){
              System.out.println("Error");
          }
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  } 
  </code></pre>
  
  <p>testFXController.java :</p>
  
  <pre><code>package testFX.view;
  
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.fxml.FXML;
  import javafx.scene.control.ListView;
  
  public class testFXController {
      @FXML ListView&lt;String&gt; listView;
      private ObservableList&lt;String&gt; obsList;
  
      public void start() {
          // create an ObservableList
          // from an ArrayList
          obsList = FXCollections.observableArrayList("Giants", "Patriots", "Jaguars");
          listView.setItems(obsList);
      }
  }
  </code></pre>
  
  <p>test.fxml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.control.ListView?&gt;
  &lt;AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1"
      fx:controller="view.testFXController"&gt;
      &lt;ListView fx:id="listView" 
          AnchorPane.topAnchor="10"
          AnchorPane.leftAnchor="10" 
          AnchorPane.rightAnchor="10"
          AnchorPane.bottomAnchor="10" /&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>When I run the testFX.java, the system prints:  </p>
  
  <pre><code>after set location  
  Error
  </code></pre>
  
  <p>This is the professor's code and I cannot seem to get it running. I realized that the main problem is in the line of code <code>AnchorPane root = (AnchorPane)loader.load();</code> but I have no idea how to fix this, can someone help?</p>