0

I'm trying to pass data from one javafx controller to another by calling a function in the new controller but every time I do so I just get a load of errors and mostly NullPointerException and have no idea why.

// admin controller
public class AdminController implements Initializable{

    @FXML 
    private Button newTermButton;

    private String error;

    private Stage stage;

    @Override
    public void initialize(URL location, ResourceBundle resources){
    }

    //buttons
    @FXML 
    public void newTermButton() throws IOException {

        FXMLLoader loader = new FXMLLoader();

        loader.setLocation(getClass().getResource("../term/Term.fxml"));

        try {
            loader.load();
        } catch (IOException ex) {
            // error
        }

        TermController tmp = loader.getController();

        //error with this line
        tmp.newTerm();

        javafx.scene.Parent p = loader.getRoot();
        Stage stage = new Stage();
        stage.setScene(new Scene(p));

        stage.showAndWait();

    }
}
// term controller
public class TermController implements Initializable{

    @FXML 
    private TextField termId;
    @FXML 
    private TextField name;

    @FXML 
    private DatePicker sDate;
    @FXML 
    private DatePicker eDate;


    public void loadTerm(int i) {
        System.out.println("load term : " + i);
    }

    public void newTerm() {
        System.out.println("new term");
    }

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        // TODO Auto-generated method stub

    }

}

I'm trying to just run a function in the TermController from the Admincontroller so the controller will know weather to load a term from my data file or create a new one.

fabian
  • 67,623
  • 12
  • 74
  • 102
Andrew Dean
  • 153
  • 3
  • 18

0 Answers0