10

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

devhicham
  • 557
  • 2
  • 6
  • 14
  • 2
    It is probable that you have defined your controller in your `Fxml` also ! – Bo Halim Jan 03 '17 at 16:01
  • you were right,, thank you, but it doesn't pass the parameters, I receive nothing – devhicham Jan 03 '17 at 16:04
  • which parameters ? – Bo Halim Jan 03 '17 at 16:05
  • it's ok now, I had an error on receiving method, thanks – devhicham Jan 03 '17 at 16:07
  • Aside: if your FXML is in a file/resource (which it almost always will be). don't call the `load(...)` method specifying a stream. If you do this, the `FXMLLoader` will not have any information about the location, and will not be able to perform [location resolution](http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#location_resolution). Instead, specify the location in the constructor: `FXMLLoader loader = new FXMLLoader(getClass().getResource("defTable.fxml"));` and then call the no-arg `load()` method: `Parent frame = loader.load();`. – James_D Jan 03 '17 at 16:12

1 Answers1

14

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!

user3810840
  • 141
  • 1
  • 4