3

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());
            }
Ömer Çelik
  • 77
  • 2
  • 11

1 Answers1

9

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.

James_D
  • 201,275
  • 16
  • 291
  • 322