我是javaFX和FXML的新手,一个星期以来,我试图将一组圆圈(它们是一些GUI指示器)绑定到某种方法上,而没有得到它。
我不完全了解:
更具体地说,我的意图是看一些动画,这意味着 看到GUI处于初始状态,然后几秒钟后 延迟我希望看到例如第一个圆圈涂成红色。 谢谢!
我当前的输出是我的GUI立即更新,并且还出现以下错误:
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();
}
}