简体   繁体   English

在FXML中创建的JavaFX中设置BorderPane的中心窗格(nullPointerException)

[英]Setting Center Pane of BorderPane in JavaFX created in FXML (nullPointerException)

I've spent some time now trying to figure out where my logic is flawed here, and have seen similar questions on here, but for some reason I keep getting a nullPointerException: 我现在花了一些时间试图弄清楚我的逻辑在哪里有缺陷,并在这里看到了类似的问题,但是由于某些原因,我一直在获取nullPointerException:

public class MainWindowController
    implements Initializable {


    public static final String SCHEDULE_MANAGER = "ScheduleManagerController";
    public static final URL SCHEDULE_MANAGER_FXML = ScheduleManagerController.class.getResource("ScheduleManager.fxml");
    final SwitchableStackPane customStackPane = new SwitchableStackPane();

    @FXML 
    Button btnScheduleManager; // Value injected by FXMLLoader
    BorderPane switchablePane; //Value injected by FXMLLoader


    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
        assert btnScheduleManager != null : "fx:id=\"ScheduleManager\" was not injected: check your FXML file 'HOECTool.fxml'.";
        assert switchablePane != null : "fx:id=\"mainPane\" was not injected: check your FXML file 'HOECTool.fxml'.";


            customStackPane.loadScreen(SCHEDULE_MANAGER, SCHEDULE_MANAGER_FXML);

            switchablePane.setCenter(customStackPane);

    }

This throws a nullPointer exception: switchablePane.setCenter(customStackPane); 这将引发nullPointer异常:switchablePane.setCenter(customStackPane);

Sorted, me being an idiot. 排序,我是个白痴。 This did it: 做到了:

 @FXML 
    Button btnScheduleManager; // Value injected by FXMLLoader
@FXML
    BorderPane switchablePane; //Value injected by FXMLLoader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM