title: label.setText NullPointerException
body: <p>Hi first time here but here goes:</p>
  
  <p>I have a JavaFX application that changes the FXML UI labels dynamically and the data is pulled from a Player class.</p>
  
  <p>The two classes in question are <code>Player.java</code> and <code>InterfaceHandler.java</code>.</p>
  
  <p>The player class stores player details and I want to pass the details to the Interface class which sets the text on the labels.</p>
  
  <p>As a test my FXML UI just has a button and two labels.</p>
  
  <p>If it click the button it calls the <code>handleButton</code> method it sets <code>locationLabel</code> to "Town" fine.</p>
  
  <p>However if I call the <code>locationLabel()</code> method in my Player class I get a NullPointerException when <code>nameLabel.setText(name)</code> is called. Through debugging I find that the name string in the Interface class is what it should be "Dan".</p>
  
  <p>Can anyone help?</p>
  
  <p>Main class:</p>
  
  <pre><code>public class Main extends Application {
  
      public void start(final Stage mainStage) throws Exception {
  
          Parent root = FXMLLoader.load(getClass().getResource("MainScreen.fxml"));
          Scene scene = new Scene(root);
          mainStage.setTitle("Main Screen");
          mainStage.setScene(scene);
          mainStage.show();    
      }
  
  public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Player class:</p>
  
  <pre><code>public class Player{
  
  InterfaceHandler ui = new InterfaceHandler();   
  
   public void setNameLabel() {
  
      String name = "Dan";
      ui.setName(name);
  }
  </code></pre>
  
  <p>InterfaceHandler class:</p>
  
  <pre><code>    public class InterfaceHandler implements Initializable {
  
         public Label nameLabel;
         public Label locationLabel;    
  
  public void handleButton(ActionEvent event) throws IOException {        
  
          locationLabel.setText("Town");
      }
  
  public void setName(String name){       
          nameLabel.setText(name);
      }    
  }
  </code></pre>
  
  <p>MainScreen.fxml:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
      &lt;?import java.lang.*?&gt;
      &lt;?import java.net.*?&gt;
      &lt;?import java.util.*?&gt;
      &lt;?import javafx.scene.*?&gt;
      &lt;?import javafx.scene.control.*?&gt;
      &lt;?import javafx.scene.effect.*?&gt;
      &lt;?import javafx.scene.image.*?&gt;
      &lt;?import javafx.scene.layout.*?&gt;
      &lt;?import javafx.scene.text.*?&gt;
  
      &lt;AnchorPane id="AnchorPane" prefHeight="629.0" prefWidth="600.0" snapToPixel="true" style="-fx-background-color:  beige;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="application.InterfaceHandler"&gt;
        &lt;children&gt;            
          &lt;Button fx:id="button1" layoutX="512.0" layoutY="381.0" minWidth="14.0" mnemonicParsing="false" onAction="#handleButton" prefHeight="30.0" prefWidth="51.0" text="Town" visible="true" /&gt;        
  
          &lt;Label fx:id="nameLabel" layoutX="57.0" layoutY="8.0" prefWidth="216.0" text="blank" /&gt;
          &lt;Label fx:id="locationLabel" layoutX="68.0" layoutY="27.0" prefWidth="193.0" text="blank" /&gt;
        &lt;/children&gt;
      &lt;/AnchorPane&gt;
  </code></pre>