JavaFX错误:已指定控制器值 [英] JavaFX Error: Controller value already specified

查看:544
本文介绍了JavaFX错误:已指定控制器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打开一个新的表单窗口。但我想在构造函数中指定一些值。

I'm trying to open a new form window. But I want to assign some values in the constructor.

我尝试的代码:

fxmlLoader.setRoot(null);

fx:root(DbForm.fxml)

fx:root (DbForm.fxml)

错误:

已指定控制器值。
file:/ C:/Users/Admin/Documents/NetBeansProjects/SeleniumWebTest/dist/run685287776/SeleniumWebTest.jar!/seleniumwebtest/DbForm.fxml:14

Controller value already specified. file:/C:/Users/Admin/Documents/NetBeansProjects/SeleniumWebTest/dist/run685287776/SeleniumWebTest.jar!/seleniumwebtest/DbForm.fxml:14

try {

     DbFormController dbYapCont = new DbFormController("s", "s", "s", "s");
     FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("DbForm.fxml"));

     fxmlLoader.setController(dbYapCont);
     Pane root = (Pane) fxmlLoader.load();
     Stage stage = new Stage();
     stage.setScene(new Scene(root));
     stage.show();
     } catch (Exception e) {
                System.out.println(e.getMessage());
            }


推荐答案

删除<$ c $来自FXML文件的c> 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错误:已指定控制器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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