I'm trying to make an app that checks the price of a product every minute.
In my test code it looks like this:
package sample;
import javafx.stage.Stage;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
import static sample.Controller.updateTicker;
public class MyTask{
public Label helloWorld;
public void criarTimer(Stage primaryStage) {
int segundos = 10;
int segundosParaComecar = 0;
int segundosParaCapturar = segundos*1000;
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
helloWorld.setText(updateTicker());
}
};
timer.schedule(timerTask, segundosParaComecar, segundosParaCapturar);
}
}
But I'm having the following Error log and I do not know how to resolve:
Exception in thread "Timer-0" java.lang.NullPointerException at sample.MyTask $ 1.run (MyTask.java:23) at java.util.TimerThread.mainLoop (Timer.java:555) at java.util.TimerThread.run (Timer.java:505)
And error occurs when you set the new String in the Label. The updateTicker()
method is returning String as expected.