JafaFx Load FXML file Error Null Pointer Exception

2019-09-09 06:52发布

i have this Exception whith no difinition of the error when i am trying to load a window from a button login. before it worked fine, but now i dont know why it shoing this error java.lang.NullPointerException, there is only this line in the console , so i couldnt find whats wrong. hears my files .

<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>

and for the function who lunchs the view in a class Named 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");

    }

and about the controller of the Splitpane view class named MainEntreController, when i click on logni it shows me this Eception java.lang.NullPointerException

0条回答
登录 后发表回答