JavaFX error: specified controller value

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

Codes I tried:

fxmlLoader.setRoot(null);

fx: root (DbForm.fxml)

Error:

The controller value is 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
source share
1 answer

Remove the attribute fx:controllerfrom the FXML file. This attribute is an instruction for FXMLLoadercreating a new controller: since you already set it by calling setController, this is inconsistent.

+4
source

Source: https://habr.com/ru/post/1665639/


All Articles