Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javafx exception : Controller value already specified

Tags:

javafx

I'm calling a method to load a window by passing some parameters to a specific internal method of this window, but I've got 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 don't understand why it consider that the controller is already set? and how to fix that ? thank you

like image 428
devhicham Avatar asked Jan 03 '17 15:01

devhicham


1 Answers

Remove the fx:controller attribute from the FXML file. That attribute is an instruction to the FXMLLoader to create a new controller: since you have already set one by calling setController it is contradictory.

JavaFX Error: Controller value already specified

This guy answered it ^ Props to him!

like image 153
user3810840 Avatar answered Oct 11 '22 22:10

user3810840