2013-12-07 3 views
0

Я генерироваться FXML в Scene Builder:LoadException с 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 

Что это значит и как это можно исправить Это?

+0

В таких случаях я удаляю вещи простым текстовым редактором; начиная с последнего, что (вы помните, что) вы коснулись. Также полезно применять директиву include и «_component-ize_» вы _scenes (если можете). Таким образом, вы/в конечном итоге можете изолировать основную причину. – will

ответ

0

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

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

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

+0

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

0

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

Смежные вопросы