title: Constant label updation from different class in javafx-fxml
body: <p>I am unable to change the text of my label from other class.
  I need to constantly update date and time on the main screen, while I may be able to perform other functions too, simultaneously.
  I have used a <em>TimeSetting</em> class, which extends Thread and in it's run() method, I've called the updation command in an infinite loop, using setText() and then slept the method for a second.
  But on running this, nothing happens and on closing the output window, I get an <strong>error</strong> saying <strong><em>NullPointerExcpetion</em></strong></p>
  
  <p>Here's the code for the two classes :
  FXMLDocumentController.java</p>
  
  <pre><code>package crt;
  
  import java.io.IOException;
  import java.net.URL;
  import java.util.Date;
  import java.util.ResourceBundle;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.fxml.Initializable;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.control.Label; 
  import javafx.stage.Modality;
  import javafx.stage.Stage;
  import javafx.stage.StageStyle;
  
  public class FXMLDocumentController extends Thread implements Initializable     
  {
  @FXML
  protected Label check;
  @FXML
  **protected Label date;**
  @FXML
  protected Label time;
  @FXML
  protected Label RRRR;
  @FXML
  protected Label DDDD;
  @FXML
  protected Label SSSS;
  @FXML
  protected Label temp;
  @FXML
  protected Label maxtemp;
  @FXML
  protected Label mintemp;
  
  @FXML
  private void handleButtonAction(ActionEvent event) throws IOException {
          //dc.setDate(date.textProperty().bind(valueproperty));
  
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("menu.fxml"));
          Parent root1 = (Parent) fxmlLoader.load();
          Stage stage = new Stage();
          stage.initModality(Modality.APPLICATION_MODAL);
          stage.initStyle(StageStyle.UNDECORATED);
          stage.setTitle("MENU");
          stage.setScene(new Scene(root1));  
          stage.show();
   }
  @Override
  public void initialize(URL url, ResourceBundle rb)  {
  }
  </code></pre>
  
  <p>FXMLDocument.fxml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;?import javafx.scene.control.Button?&gt;
  &lt;?import javafx.scene.control.Label?&gt;
  &lt;?import javafx.scene.control.ProgressBar?&gt;
  &lt;?import javafx.scene.layout.AnchorPane?&gt;
  &lt;?import javafx.scene.text.Text?&gt;
  
  &lt;AnchorPane id="AnchorPane" prefHeight="367.0" prefWidth="510.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="crt.FXMLDocumentController"&gt;
  &lt;children&gt;
      &lt;Button fx:id="button" layoutX="387.0" layoutY="302.0" minHeight="25.0" minWidth="80.0" onAction="#handleButtonAction" onTouchPressed="#handleButtonAction" text="Menu" /&gt;
      &lt;Label fx:id="date" layoutX="56.0" layoutY="64.0" minHeight="25.0" minWidth="80.0" /&gt;
    &lt;Label fx:id="time" layoutX="361.0" layoutY="64.0" minHeight="25.0" minWidth="80.0" text="S" /&gt;
    &lt;Label fx:id="RRRR" layoutX="76.0" layoutY="100.0" minHeight="25.0" minWidth="70.0" /&gt;
    &lt;Label fx:id="DDDD" layoutX="195.0" layoutY="100.0" minHeight="25.0" minWidth="70.0" /&gt;
    &lt;Label fx:id="SSSS" layoutX="314.0" layoutY="100.0" minHeight="25.0" minWidth="70.0" /&gt;
    &lt;Text layoutX="136.0" layoutY="163.0" strokeType="OUTSIDE" strokeWidth="0.0" text="TEMP :-" /&gt;
    &lt;Label fx:id="temp" layoutX="275.0" layoutY="156.0" minHeight="25.0" minWidth="70.0" text="A" /&gt;
    &lt;Text layoutX="136.0" layoutY="203.0" strokeType="OUTSIDE" strokeWidth="0.0" text="MAX TEMP :-" /&gt;
    &lt;Label fx:id="maxtemp" layoutX="275.0" layoutY="188.0" minHeight="25.0" minWidth="70.0" text="B" /&gt;
    &lt;Text layoutX="136.0" layoutY="243.0" strokeType="OUTSIDE" strokeWidth="0.0" text="MIN TEMP :-" /&gt;
  
    &lt;Label fx:id="maxtemp" layoutX="275.0" layoutY="225.0" minHeight="25.0" minWidth="70.0" text="C" /&gt;
    &lt;ProgressBar layoutX="401.0" layoutY="21.0" prefHeight="18.0" prefWidth="70.0" progress="0.0" /&gt;
    &lt;Button fx:id="startbutton" layoutX="14.0" layoutY="18.0" mnemonicParsing="false" onAction="#startstart" text="START" /&gt;
    &lt;Label fx:id="check" layoutX="42.0" layoutY="306.0" /&gt;
  
  &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>
  
  <p>TimeSetting.java</p>
  
  <pre><code>package crt;
  import java.util.Date;
  public class TimeSetting extends Thread {
  @Override
  public void run()
  {
      FXMLDocumentController fdc = new FXMLDocumentController();
   //       fdc.load();
      int i=0;
      while(true)
      {
          Date d = new Date();
          fdc.date.setText("fd" + i);
          i++;
          try
          {
              Thread.sleep(1000);
          }
          catch(InterruptedException e)
          {
          }
      }
  }
  }
  </code></pre>
  
  <p>CRT.java    </p>
  
  <pre><code>package crt;
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  public class CRT extends Application {
  
  @Override
  public void start(Stage stage) throws Exception {
      Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
  
      Scene scene = new Scene(root);
  
      stage.setScene(scene);
      stage.show();
  }
  
  
  public static void main(String[] args) throws InterruptedException {
      launch(args);
      TimeSetting ts = new TimeSetting();
      ts.start();
  }
  
  }
  </code></pre>