LoadException с FXML, созданным с помощью Scene Builder

Я создал FXML в Scene Builder:

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

<?scenebuilder-preview-i18n-resource ../lang/ru_RU.properties?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="mainStagePane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="UI.MainStageController">
  <children>
    <SplitPane dividerPositions="0.6596244131455399" focusTraversable="true" prefHeight="-1.0" prefWidth="1280.0" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="160.0">
      <items>
        <AnchorPane id="rootPane" fx:id="pane3d" prefHeight="930.0" prefWidth="1280.0" />
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
          <children>
            <Accordion id="accordeon" fx:id="accordion" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
              <panes>
                <TitledPane animated="true" text="%3dSceneSettings" fx:id="x2">
                  <content>
                    <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
                      <children>
                        <Slider fx:id="farClipSlider" layoutY="50.0" majorTickUnit="10.0" max="100.0" min="-100.0" minorTickCount="1" prefWidth="337.0" showTickLabels="true" showTickMarks="true" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="75.0" />
                        <TextField layoutY="14.0" prefWidth="55.0" AnchorPane.rightAnchor="217.0" />
                        <Slider fx:id="distanceSlider" blockIncrement="25.0" layoutX="14.0" layoutY="133.0" majorTickUnit="50.0" max="500.0" min="-500.0" minorTickCount="25" prefWidth="399.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" />
                        <VBox layoutY="364.0" prefHeight="200.0" prefWidth="100.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0">
                          <children>
                            <HBox prefHeight="-1.0" prefWidth="-1.0">
                              <children>
                                <Label text="Label" />
                                <TextField prefWidth="55.0" />
                              </children>
                            </HBox>
                            <Slider fx:id="nearClipSlider" blockIncrement="1.0" majorTickUnit="10.0" max="100.0" min="-100.0" minorTickCount="1" prefWidth="338.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="0.0" />
                          </children>
                        </VBox>
                        <Label layoutX="104.0" layoutY="17.0" text="Label" />
                      </children>
                    </AnchorPane>
                  </content>
                </TitledPane>
                <TitledPane animated="true" expanded="false" text="%3dModelSettings" fx:id="x1">
                  <content>
                    <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
                  </content>
                </TitledPane>
              </panes>
            </Accordion>
          </children>
        </AnchorPane>
      </items>
    </SplitPane>
    <ToolBar maxHeight="30.0" minHeight="30.0" prefHeight="30.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
      <items>
        <ProgressBar fx:id="loadProgressBar" disable="false" prefWidth="200.0" progress="0.0" visible="true" />
      </items>
    </ToolBar>
    <TabPane prefHeight="160.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
      <tabs>
        <Tab text="%file">
          <content>
            <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
              <children>
                <Button alignment="CENTER" graphicTextGap="4.0" mnemonicParsing="false" prefHeight="90.0" prefWidth="90.0" text="%openFile" textAlignment="CENTER" textOverrun="ELLIPSIS" underline="false" wrapText="true" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="14.0" />
                <Separator layoutX="170.0" orientation="VERTICAL" prefHeight="200.0" AnchorPane.bottomAnchor="10.0" AnchorPane.topAnchor="10.0" />
              </children>
            </AnchorPane>
          </content>
        </Tab>
        <Tab text="%analysis">
          <content>
            <AnchorPane id="Content" minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
              <children>
                <Button mnemonicParsing="false" prefHeight="90.0" prefWidth="90.0" text="Button" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="14.0" />
              </children>
            </AnchorPane>
          </content>
        </Tab>
      </tabs>
    </TabPane>
  </children>
</AnchorPane>

Но вдруг я получил следующее исключение:

javafx.fxml.LoadException: 
/D:/Projects/CastAnalytics/out/production/CastAnalytics/UI/MainStage.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2592)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2570)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2416)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3160)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3121)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3094)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3070)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3062)
    at core.CastAnalytics.start(CastAnalytics.java:32)
    at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
    at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:331)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:297)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:294)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(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.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.lang.NullPointerException
    at UI.MainStageController.set(MainStageController.java:98)
    at UI.MainStageController.initialize(MainStageController.java:34)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2523)
    ... 18 more

Что это значит и как я могу это исправить?


person Eugene    schedule 07.12.2013    source источник
comment
В таких случаях я удаляю вещи простым текстовым редактором; начиная с последней вещи, к которой (вы помните это) вы прикоснулись. Также полезно применить директиву include и 'component-ize' к вашим _сценам (если можете). Таким образом, вы в конечном итоге сможете изолировать первопричину.   -  person will    schedule 16.06.2016


Ответы (2)


Итак, у вас есть нулевой указатель в строке 98 MainStageController....

Если бы мне пришлось угадывать, я бы сказал, что одна из переменных @FXML, которые вы определили в своем контроллере, не имеет того же имени, что и в вашем файле FXML, поэтому вы получаете NPE.

Вам нужно будет вставить соответствующий код MainStageController.java, чтобы кто-нибудь мог узнать больше.

person jhsheets    schedule 07.12.2013
comment
Это было первое, о чем я подумал... но все проверил, все переменные имеют одинаковые имена и в FXML, и в java файлах. Вот почему я прошу помощи здесь. - person Eugene; 08.12.2013

Пожалуйста, опубликуйте оскорбительную строку или SSCE, если это возможно. Я согласен с jhsheets и вашим подходом, дважды сверяющим имена переменных с вашими именами fx: id. Я сам столкнулся с этой точной ошибкой/ситуацией точно в том же месте (в методе инициализации, пытающемся выполнить некоторую инициализацию после загрузки), где небольшая опечатка в моем fx: I вызвала NPE. Но было бы хорошо знать, что происходит в методе set, где возникает NPE.

person chooks    schedule 08.12.2013