将参数从JavaFx Controller发送到另一个时发生java.lang.NullPointerException

时间:2016-03-31 12:23:37

标签: java nullpointerexception javafx-8 scenebuilder

正如标题中提到的那样,我正试图将参数从控制器发送到另一个但我得到了java.lang.NullPointerException 这是我想从中获取userId的控制器。

public class EnseignantOverViewController implements Initializable {
    @FXML
    private Label niveau;
    @FXML
    private Label matiere;
    @FXML
    private Label groupe;
    @FXML
    private ComboBox<String> comboNiveau;
    @FXML
    private ComboBox<String> comboMatiere;
    @FXML
    private ComboBox<String> comboGroupe;
    @FXML
    private Button Valider;
    @FXML
    private Long userId;

    EnsNivHome ensNiv = new EnsNivHome();

    // List<Integer> myObservableList=ensNiv.niveauEns(login, password);
    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        // TODO Auto-generated method stub

    }

    public Long getUserId() {
        return this.userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId ;
    }
}

这是我想要获取UserId的控制器

Long testResp = resp.connecter(login.getText(), password.getText());
if (testEns != null && comboprofil.getValue().equals("Enseignant")) {
        Stage stage1 = (Stage) seConnecter.getScene().getWindow();

        FXMLLoader loader = new FXMLLoader(getClass().getResource("EnseignantView.fxml"));

        Pane pane = (Pane) loader.load();
        EnseignantOverViewController ensController = loader.<EnseignantOverViewController> getController();
        System.out.println("la valeur de testEns est: " + testEns);
        ensController.setUserId(testEns);

        Scene scene = new Scene(pane);
        // on peut faire new stage

        stage1.setScene(scene);
        stage1.show();
}

我得到了ensController.setUserId(testEns)的NullPointerException,但是当我输出testEns的值时,我得到了正确的值。

0 个答案:

没有答案