Javafx exception: controller value already specified

I call the method to load the window, passing some parameters for the specific internal method of this window, but I have this exception:

GRAVE: null
javafx.fxml.LoadException: Controller value already specified.
unknown path:12

here is my method

public void openDef(String sys, String comp, String code) throws Exception {
    Stage defStage = new Stage();
    FXMLLoader loader = new FXMLLoader();
    DefTableController cont = new DefTableController();//calling class controller
    loader.setController(cont);
    Parent frame = loader.load(getClass().getResource("defTable.fxml").openStream());
    cont.getSysChoice(sys, comp, code);//call the method by passing parameters
    Scene sceneDef = new Scene(frame);

    defStage.setTitle("Défaillance du " + comp);
    defStage.setScene(sceneDef);
    defStage.show();
}

I do not understand why he believes that the controller is already installed? and how to fix it? thank

+4
source share
1 answer

Remove the fx: controller attribute from the FXML file. This attribute is an instruction for FXMLLoader to create a new controller: since you already set it by calling setController, this is inconsistent.

JavaFX error: controller value already specified

This guy answered this ^ Supports him!

+4
source

Source: https://habr.com/ru/post/1665638/


All Articles