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 !!