I'm making a mod manager for a game, and I'm running into issues where I'm trying to call methods, but they cant be called because the controllers havent been initialized in time.
I use SceneBuilder wherever I can, I have a mix of manual loading because I am inserting entire FXMLs into the scene.
This is where the problem occurs: (in my ModListController)
    protected void handleModDoubleClick() {
        selectionList.clear();
        selectedMod = LV_ModList.getSelectionModel().getSelectedItem();
        if (selectedMod != null) {
            System.out.println("Selected mod: " + selectedMod); //TEMP @TODO
            ModFile mf = new ModFile(selectedMod);
            System.out.println("LOADING...");
            mf.retrieveData();
            xlc.setXmlListController(this); //THIS IS THE 'PROBLEM LINE'
            xlc.setXmlList(mf);
            selectionList.clear();
            System.out.println("DONE");
        }
    }
Somehow modListController is returning null when setting it.
in my XmlListController, I use this to set the controller instance:
    public void setXmlListController(ModListController mlc){
        mlc.setXmlListController(this);
    }
and it's called here in my MainController:
    private void initialize() { //This always loads last.
            System.out.println("MainContoller loaded");
            Platform.runLater(() -> {
                System.out.println("MainContoller loaded - runlater");
                ModListController mlc = new ModListController();
                uiHbox.getChildren().clear();
                uiHbox.getChildren().add(mlc.getListView()); //Adds ModList-View to scene
                FXMLLoader xmlUiLoader = new FXMLLoader(getClass().getResource("XmlList-View.fxml"));
                try {
                    Parent xmlListViewRoot = xmlUiLoader.load();
                    anchorPane.getChildren().add(xmlListViewRoot);
                    uiHbox.getChildren().add(anchorPane); //Adds XmlList-View to scene
                } catch (IOException e){
                    e.printStackTrace();
                }
                XmlListController xlc = xmlUiLoader.getController(); // Get the controller instance
                modListController.setXmlListController(xlc); //THIS IS WHERE IT'S CALLED.
                mlc.resetModList();
                handleModListClicks(mlc);
            });
I've put this inside of my ModListController to see if it was ever called:
    @FXML
    public void initialize(){
        System.out.println("Modlistcontroller loaded");
    }
And for reference, this is my method where the problem originated:
    public void setXmlList(ModFile mf){
        LV_XmlList.setDisable(false);
        mf.populateXmlList();
        xmlFileNames.clear();
        for (XmlFile xml : mf.modifiableXmlList){
            xmlFileNames.add(xml.fileName);
        }
        LV_XmlList.setItems(xmlFileNames);
    }
I was making another instance of the XmlListController in an attempt to make a nasty workaround, but the listview does not populate, likely because of the second instance.
here is the output to the console:
MainController loaded
MainController loaded - runlater
XmlListController loaded
XmlListController loaded - runlater
As you can tell, the ModListController is never initialized.
here is the Exception:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "com.rechaa.fs22mm.ModListController.setXmlListController(com.rechaa.fs22mm.XmlListController)" because "this.modListController" is null
    at com.rechaa.fs22mm/com.rechaa.fs22mm.MainController.lambda$initialize$0(MainController.java:79)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:833)
despite all this, my modListController loads as expected in the UI if I remove the line that causes the exception, but it says this.xlc is null.
Any input is appreciated. I am stumped. I'm a novice at programming so if you see any room for improvement in general, I'll welcome the recommendations. I'd be happy to include any other code if needed. Obviously, I really want to avoid sharing the entirety of it though. Thanks again
I've tried: getting and setting controller instances double checked FXML paths commenting out bulks of code
 
    