title: javafx fxml is null outside initialize()
body: <p>In this code:</p>
  
  <pre><code>public class ESM extends Application {
  
  private Stage primaryStage;
  
  @FXML 
  private ToolBar mainToolBar;
  
  
  @Override
  public void start(final Stage stage) throws Exception {
      try{
          this.primaryStage = stage;
          Parent root = FXMLLoader.load(getClass().getResource("/nz/co/great_ape/esm3/main_window.fxml"));
  
          Scene scene = new Scene(root, 800, 700);            
          //  Setup main stage to be full screen, no min or max buttons.
          //  TODO:  How will this handle multiple screens?  Apparently not well :-(
          Screen screen = Screen.getPrimary();
          Rectangle2D bounds = screen.getVisualBounds();
          primaryStage.setX(bounds.getMinX());
          primaryStage.setY(bounds.getMinY());
          primaryStage.setWidth(bounds.getWidth());
          primaryStage.setHeight(bounds.getHeight());
          primaryStage.initStyle(StageStyle.UNDECORATED); 
          primaryStage.setTitle("ESM three");
          primaryStage.setScene(scene);
          primaryStage.show();
          System.out.println("This will fail because mainToolBar is null.  Why?");
          assert mainToolBar != null : "fx:id=\"mainToolBar\" was null check your FXML ";
      } catch (Exception ex) {
          Logger.getLogger(ESM.class.getName()).log(Level.SEVERE, null, ex);
      }           
  }
  
  
  
  /**
   * Use initialize() to setup widgets from scenebuilder files, it is
   * called by FXMLLoader.
   */
  @FXML
  public void initialize(){
      System.out.println("initialize() But when here all is good and mainToolBar is a ToolBar.");
      assert mainToolBar != null : "fx:id=\"mainToolBar\" was null check your FXML ";     
  }
  
  /**
   * The main() method is ignored in correctly deployed JavaFX application.
   * main() serves only as fallback in case the application can not be
   * launched through deployment artifacts, e.g., in IDEs with limited FX
   * support. 
   *
   * @param args The command line arguments.
   */
  public static void main(String[] args) {
      launch(args);
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I cant see why it's got a value in the initialise() but in the start it's null.  When debuging it's clear that initiialize() is called by FXMLLOader from inside start()</p>
  
  <p>I was going to post the fxml but it does not seem to work as nothig shows in the preview.  Any way, it's a real basic file, a BordePane and a ToolBar.  </p>
  
  <p>Any clues?</p>