我试图更改应用程序中的场景,并且加载场景后需要直接更新其中一个节点,但问题是该节点尚未初始化,所以我总是得到 NPE。如何强制初始化节点或等到所有节点都已初始化后再调用该 ndoe 的方法我从未成功尝试调用节点,但是如果我在事件中调用节点(例如按下按钮),它似乎确实有效。package za.holmes.PAT;import java.net.URL;import java.util.ResourceBundle;import javafx.event.ActionEvent;import javafx.fxml.FXML;import javafx.fxml.FXMLLoader;import javafx.fxml.Initializable;import javafx.scene.control.Button;import javafx.scene.control.Label;import javafx.scene.control.PasswordField;import javafx.scene.control.TextField;import javafx.scene.layout.AnchorPane;public class EventHandler implements Initializable { @FXML private AnchorPane changePane; @FXML private TextField IDField; @FXML private PasswordField passField; @FXML private Label errorField; @FXML private Label nameText; private User currentUser; @Override public void initialize(URL url, ResourceBundle resourceBundle) { }// @FXML// private void initialize() {// } @FXML private void start(ActionEvent event) { ((Button) event.getSource()).setDisable(true);; System.out.println("Program started"); try { System.out.println("Connecting to database"); Class.forName("za.holmes.PAT.DataHandler"); } catch (Exception e) { e.printStackTrace(); } updateScreen("Login.fxml"); } private void updateScreen(String fileName) { try { FXMLLoader loader = new FXMLLoader(); AnchorPane pane = (AnchorPane)loader.load(Oldage.class.getResourceAsStream("/scenes/" + fileName)); changePane.getChildren().setAll(pane); } catch (Exception e) { e.printStackTrace(); } }
添加回答
举报
0/150
提交
取消