javafx异常:已指定控制器值 [英] javafx exception : Controller value already specified

查看:152
本文介绍了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

这是我的方法

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

推荐答案

从FXML文件中删除fx:controller属性。该属性是对FXMLLoader创建一个新的控制器的指令:既然你已经设置一个通过调用setController很矛盾

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错误:控制器值已经指定

此人回答了它^道具给他!

This guy answered it ^ Props to him!

这篇关于javafx异常:已指定控制器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆