JafaFx加载FXML文件错误空指针异常

时间:2016-01-16 15:54:03

标签: javafx javafx-2 fxml scenebuilder fxmlloader

我有这个例外,当我尝试从按钮登录加载窗口时没有错误的定义。在它工作正常之前,但现在我不知道为什么它出现这个错误java.lang.NullPointerException,在控制台中只有这一行,所以我无法找到什么错误。听到我的文件。

<SplitPane dividerPositions="0.5" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controller.MainEntredController">
 <items>
   <MenuBar>
    <menus>
      <Menu mnemonicParsing="false" text="File">
        <items>
          <MenuItem mnemonicParsing="false" text="Close" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Edit">
        <items>
          <MenuItem mnemonicParsing="false" text="Delete" />
        </items>
      </Menu>
      <Menu mnemonicParsing="false" text="Help">
        <items>
          <MenuItem mnemonicParsing="false" text="About" />
        </items>
      </Menu>
    </menus>
  </MenuBar>
  <TabPane prefHeight="200.0" prefWidth="200.0"  tabClosingPolicy="UNAVAILABLE">
    <tabs>
      <Tab text="Home" />
    </tabs>
  </TabPane>
 </items>
</SplitPane>

以及在名为MainController的类中午餐视图的函数

public void loginBtnClick(ActionEvent event) throws Exception{
    String Usern = username.getText();
    String pass = txtpassword.getText();
     try {
         if( con.LoginDatabase(Usern, pass)){
                lblstatus.setText("Login Successfully");
                Stage primaryStage1 = new Stage();

            Parent root = FXMLLoader.load(getClass().getResource("/application/viewsfx/MainEntredHome.fxml"));

                Scene scene = new Scene(root);
                scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
                primaryStage1.setScene(scene);
                primaryStage1.show();

                // closing the login scene
                 Stage stage = (Stage) btnlogin.getScene().getWindow();
                    stage.close();

                }else {
                    lblstatus.setText("Login failed");
                }
    } catch (Exception e) {
        System.out.println(e);
        System.out.println("ani hna mebloki");

    }

关于名为MainEntreController的Splitpane视图类的控制器, 当我点击logni时,它会向我展示这个Eception java.lang.NullPointerException

0 个答案:

没有答案