11

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

5
  • 2
    It is probable that you have defined your controller in your Fxml also ! Commented Jan 3, 2017 at 16:01
  • you were right,, thank you, but it doesn't pass the parameters, I receive nothing Commented Jan 3, 2017 at 16:04
  • which parameters ? Commented Jan 3, 2017 at 16:05
  • it's ok now, I had an error on receiving method, thanks Commented Jan 3, 2017 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. 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();. Commented Jan 3, 2017 at 16:12

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.