0

I tried to change the value of a 'label' field using setText() method which is in a method called by timer.Totally, I have 3 Classes 1)FXMLDocumentController 2) checkInternetStatus and 3) InternetConnectivity as I've shown below.

At First,I called timer in 'initialize' method of FXMLDocumentController as below Timer timer = new Timer(); timer.schedule(new checkInternetStatus(), 0, 5);

Then, it calls runnable in the checkInternetStatus class and returns to a method which is in 1st class. Here getInternetStatus() is a method in InternetConnectivity class which returns a boolean.

class checkInternetStatus extends TimerTask {
  InternetConnectivity obj = new InternetConnectivity();
  FXMLDocumentController obj2 = new FXMLDocumentController();

  @Override
  public void run() {
    javafx.application.Platform.runLater(new Runnable() {
        public void run() {
            obj2.checkInternetStatusFXML(obj.getInternetStatus());
        }
    });
  }

But it returns Null Pointer Exception like below

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at the line

statusText.setText("desired_text"); 

which is in the method in FXMLDocumentController which sets desired text. Can anyone help, Thanks in advance !!

ksa
  • 47
  • 8
  • you should provide some code or people can't answer you but with general and possibly vague answers! My guess is somehow you failed to inject the label to controller correctly. Did you use @FXML? – Omid Jan 14 '16 at 13:26
  • @omid thanks,i've edited my post and included some details, can you look at it and help me... – ksa Jan 14 '16 at 14:25

0 Answers0