JavaFX Error: Controller value already specified

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

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

The codes I tried:

fxmlLoader.setRoot(null);

fx:root (DbForm.fxml)

Error:

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());             }

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!