I'm new to javaFX and FXML and for a week now I'm trying to bind a collection of circles (they are some GUI indicators) to some method, and don't get it.
I did not fully understand:
- Where should I initialize my circles?
- How to make my GUI update after the first Main.stage.show?
- Should I use animation for that?
To be more specific my intention is to see some animation, that means seeing the GUI in its initial state and then after a few seconds of delay I wish to see the first circle painted red for example. Thanks!
My current output is that my GUI updates instantly and I also get the following error:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.UIController.lambda$changeCircleColor$0(UIController.java:87)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.UIController.lambda$changeCircleColor$1(UIController.java:93)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
יונ 09, 2019 9:06:39 PM javafx.fxml.FXMLLoader$ValueElement processValue
WARNING: Loading FXML document with JavaFX API of version 11.0.1 by JavaFX runtime of version 8.0.191
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.ArrayList;
public class Main extends Application {
public static Stage stage = new Stage();
public static Parent root = new Parent() {
};
/**
* the main method of the program
*/
public static void main(String args[]) {
UIController uiController = new UIController();
uiController.changeCircleColor();
Application.launch(Main.class, args);
}
public void start(Stage stage){
this.stage = stage;
FXMLLoader loader = new FXMLLoader();
try {
loader.setLocation(getClass().getResource("resources/UserInterface.fxml"));
this.root = loader.load();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
stage.setTitle("Troubleshooting project");
stage.setScene(new Scene(root, 900, 700));
stage.show();
}
}