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

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

错误:

控制器值已指定.文件:/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());
            }

推荐答案

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

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