I have been working on this part of code for a day and just can't figure out why it always generates error.

I have a controller and FXML. They worked perfectly. Then it came to my mind that I want to reuse this particular controller with a abstract updateSelect() function. Therefore, I change the controller to abstract.

The code compiled just fine. Until I try to run this part of code.

@FXML
private void mnuProjMember_onClick(ActionEvent event) {
    mainContent.getChildren().clear();
    FXMLLoader loader = new      FXMLLoader(getClass().getResource("PaneProjectSearch.fxml"));

    PaneProjectSearchController controller = new PaneProjectSearchController(){
        @Override
        void updateSelect(){
            System.out.println("update: !!");
        }
    };

    loader.setController(controller);
    controller.setParent(mainContent);
    fitToParent(loader);
}

It gives me following error message. Well...it's non-sense because the code will work fine again after I remove the abstract parts without even touching the FXML or other functions.

Error resolving onAction='#btnAdd_onClick', either the event handler is not in the Namespace or there is an error in the script. file:/D:/NetBeansWork/ProjCostTracking/dist/run1210215635/ProjCostTracking.jar!/ProjCostTracking/PaneProjectSearch.fxml:20

Any guidance and advise is welcomed, thanks :)

有帮助吗?

解决方案

I'm guessing that you have a private handler method in the abstract controller class. To make this work, I think the handler methods, as well as any @FXML-annotated fields, need to be directly accessible by the subclass (i.e. public or protected, or default visibility if the subclass is in the same package as the abstract controller).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top