title: JavaFX element is null in the controller
body: <p>I have an <code>ImageView imageview1</code>, in which I want to display an image loading from <code>resources</code> folder
  But my imageview is null when I run the program</p>
  <p>I saw lot of other posts saying that the problem was that people were initialising the ImageView again after FXML with something like <code>imageview1 = new ImageView();</code>, but I don't initialize it anywhere. If I try to initialise it in the start() then try to display the image, the program run fine but I don't see the image</p>
  <p>Here is my controller's code :</p>
  <pre class="lang-java prettyprint-override"><code>package com.morialog.moriamines.GUIs;
  
  import com.morialog.moriamines.Partie.Item;
  import com.morialog.moriamines.Utils;
  import javafx.application.Application;
  import javafx.application.Platform;
  import javafx.scene.image.Image;
  import javafx.scene.image.ImageView;
  import javafx.stage.Stage;
  
  public class MainMenu extends Application {
  
      public static Stage primaryStage;
      public ImageView imageview1;
  
      public static void start() {
          launch();
      }
  
      @Override
      public void start( Stage primaryStage ) {
          MainMenu.primaryStage = primaryStage;
          show();
          addImage( Item.IRON_SWORD );
          primaryStage.show();
          try {
              primaryStage.getIcons().add( new Image( String.valueOf( Utils.getResource( &quot;/logo.png&quot; ) ) ) );
          } catch( Exception e ) {
              System.out.println( &quot;Exception while loading the javaFX's icon&quot; );
              e.printStackTrace();
          }
      }
  
      public static void show() {
          primaryStage.setTitle( &quot;MoriaMines - Main menu&quot; );
          primaryStage.setScene( Utils.getSceneFromRessource( GUI.MAIN_MENU ) );
      }
  
      public void addImage( Item item ) {
          try {
              Image img = new Image( getClass().getResource( &quot;/Textures/&quot; + item.toString() + &quot;.png&quot;
                                      ).toString() );
              imageview1.setImage( img );
          } catch( Exception a ) {
              a.printStackTrace();
          }
      }
  
  }
  </code></pre>
  <p>Solution by Slaw that fixed my problem :
  You're using MainMenu as the fx:controller, then note you are ending up with two different instances of MainMenu. It's typically a bad idea to use your application class as a controller class as well</p>