0

As it is mentionned in the title, i'm trying to send parametre from a controller to another but i got java.lang.NullPointerException this is the controller i want to get userId from.

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

and this is the controller where i want to get the 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();
}

I got a NullPointerException for ensController.setUserId(testEns) but when I sys-out the value of testEns I got the correct value.

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
  • 2
    It is probably your `ensController` being null, not the `testEns`. – Loki Mar 31 '16 at 12:25
  • I agree, the controller is probably what is null. Please provide the FXML for conclusive answer, or make sure you defined the controller class (with correct fully-qualified name). – Itai Mar 31 '16 at 12:27

0 Answers0