Передача открытие второго окна по нажатию на кнопку в первом окне

Пытаюсь реализовать открытие второго окна по нажатию на кнопку в первой форме, но получаю ошибку. Что не так делаю?

Контроллер первого окна:

public class DirectoryWindowController {
    private Stage stage;
    private LuService luService = new LuService();
    private SortedList<Lu> sortedList;
    private DirectoryAddWindowController directoryAddWindowController;
    private Parent fxmlDirectoryAdd;
    private Stage addDirectoryStage;
    private FXMLLoader fxmlLoader = new FXMLLoader();

    @FXML private TableView<Lu> tabLu0;
    @FXML private TableColumn<Lu, Integer> colID;
    @FXML private TableColumn<Lu, Integer> colTag;
    @FXML private TableColumn<Lu, String> colText;
    @FXML private TableColumn<Lu, String> colCode;
    @FXML private TableColumn<Lu, Integer> colStatus;
    @FXML private TableColumn<Lu, String> colNote;
    @FXML private TableColumn<Lu, Date> colBgnDate;

    public void setStage(Stage stage) {
        this.stage = stage;
    }

    public void initialize() {
        getLu0();
    }

    private void getLu0() {
        luService.getLuWithTag0();

        getSortedListLu();

        colID.setCellValueFactory(new PropertyValueFactory<Lu, Integer>("id"));
        colTag.setCellValueFactory(new PropertyValueFactory<Lu, Integer>("tag"));
        colText.setCellValueFactory(new PropertyValueFactory<Lu, String>("text"));
        colCode.setCellValueFactory(new PropertyValueFactory<Lu, String>("code"));
        colStatus.setCellValueFactory(new PropertyValueFactory<Lu, Integer>("status"));
        colNote.setCellValueFactory(new PropertyValueFactory<Lu, String>("note"));
        colBgnDate.setCellValueFactory(new PropertyValueFactory<Lu, Date>("bgndate"));

        sortedList.comparatorProperty().bind(tabLu0.comparatorProperty());

        if (sortedList.size() != 0) {
            tabLu0.setItems(sortedList);
        }
    }

    private SortedList<Lu> getSortedListLu() {
        return sortedList = new SortedList<Lu>(luService.getLuList());
    }

    public void onAddSpravochnikType(ActionEvent actionEvent) throws IOException {
        loaderAddDirectoryWindow();

        directoryAddWindowController.setLu(new Lu());

        showAddDirectoryWindow();
    }

    private void loaderAddDirectoryWindow() {
        try {
            fxmlLoader.setLocation(getClass().getResource("/fxml/directory_add_window.fxml"));
            fxmlLoader.setController(directoryAddWindowController = new DirectoryAddWindowController((DirectoryWindowController) this));
            fxmlDirectoryAdd = fxmlLoader.load();
            directoryAddWindowController = fxmlLoader.getController();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    private void showAddDirectoryWindow() {
        if (addDirectoryStage == null) {
            addDirectoryStage = new Stage();
            addDirectoryStage.setTitle("Добавить");
            addDirectoryStage.setMaxWidth(800);
            addDirectoryStage.setMaxHeight(365);
            addDirectoryStage.initModality(Modality.WINDOW_MODAL);
            addDirectoryStage.initOwner(stage);
            addDirectoryStage.setResizable(false);
            addDirectoryStage.setScene(new Scene(fxmlDirectoryAdd));
        }

        addDirectoryStage.showAndWait();
    }
}

Контроллер второго окна:

public class DirectoryAddWindowController {
    private Stage stage;

    private Lu lu;

    private DirectoryWindowController directoryWindowController;

    @FXML
    private TextField txtName;
    @FXML
    private TextField txtCode;
    @FXML
    private DatePicker txtBgnDate;
    @FXML
    private DatePicker txtEndDate;
    @FXML
    private CheckBox checkStatus;
    @FXML
    private TextField txtNote;

    public DirectoryAddWindowController(DirectoryWindowController directoryWindowController) {
        this.directoryWindowController = directoryWindowController;
    }

    public void setStage(Stage stage) {
        this.stage = stage;
    }

    public void setLu(Lu lu) {
        if (lu == null) {
            return;
        }

        this.lu = lu;
    }
}

Разметка второго окна:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox minWidth="400.0" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <AnchorPane>
         <children>
            <VBox prefHeight="200.0" prefWidth="100.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
               <children>
                  <TextField fx:id="txtName" promptText="Введите название справочника">
                     <padding>
                        <Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
                     </padding>
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </TextField>
                  <TextField fx:id="txtCode" promptText="Введите код справочника">
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </TextField>
                  <DatePicker fx:id="txtBgnDate" promptText="Дата начала действия" VBox.vgrow="ALWAYS">
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </DatePicker>
                  <DatePicker fx:id="txtEndDate" promptText="Дата окончания действия" VBox.vgrow="ALWAYS">
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </DatePicker>
                  <CheckBox fx:id="checkStatus" mnemonicParsing="false" text="Активный">
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </CheckBox>
                  <TextField fx:id="txtNote" promptText="Комментарий">
                     <VBox.margin>
                        <Insets bottom="5.0" />
                     </VBox.margin>
                  </TextField>
                  <Button mnemonicParsing="false" onAction="#onAdd" text="Добавить">
                     <padding>
                        <Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
                     </padding>
                  </Button>
               </children>
            </VBox>
         </children>
      </AnchorPane>
   </children>
   <padding>
      <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
   </padding>
</VBox>

Ошибка:

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2597) at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:103) at javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:610) at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:770) at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at myapp.controllers.DirectoryWindowController.loaderAddDirectoryWindow(DirectoryWindowController.java:94) at myapp.controllers.DirectoryWindowController.onAddSpravochnikType(DirectoryWindowController.java:78) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Node.fireEvent(Node.java:8411) at javafx.scene.control.Button.fire(Button.java:185) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$MouseHandler.process(Scene.java:3757) at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431) at com.sun.glass.ui.View.handleMouseEvent(View.java:555) at com.sun.glass.ui.View.notifyMouse(View.java:937) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:187) at java.lang.Thread.run(Thread.java:748) Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774) at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Node.fireEvent(Node.java:8411) at javafx.scene.control.Button.fire(Button.java:185) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$MouseHandler.process(Scene.java:3757) at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431) at com.sun.glass.ui.View.handleMouseEvent(View.java:555) at com.sun.glass.ui.View.notifyMouse(View.java:937) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:187) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) ... 56 more Caused by: java.lang.NullPointerException: Root cannot be null at javafx.scene.Scene.(Scene.java:336) at javafx.scene.Scene.(Scene.java:194) at myapp.controllers.DirectoryWindowController.showAddDirectoryWindow(DirectoryWindowController.java:110) at myapp.controllers.DirectoryWindowController.onAddSpravochnikType(DirectoryWindowController.java:82) ... 66 more


Ответы (0 шт):