javafx异常:已指定控制器值

dev*_*ham 6 javafx

我正在通过将一些参数传递给此窗口的特定内部方法来调用加载窗口的方法,但我有这个异常:

GRAVE: null
javafx.fxml.LoadException: Controller value already specified.
unknown path:12
Run Code Online (Sandbox Code Playgroud)

这是我的方法

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();
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么它认为控制器已经设置好了?以及如何解决这个问题?谢谢

小智 9

从FXML文件中删除fx:controller属性.该属性是FXMLLoader创建新控制器的指令:由于您已经通过调用setController设置了一个,因此它是矛盾的.

JavaFX错误:已指定控制器值

这家伙回答了它^道具给他!