2

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 :)

Dean Chiu
  • 1,325
  • 1
  • 13
  • 13

1 Answers1

4

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).

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Yes! You are right about it! It worked! I basically replaced all the private functions in the controller to protected. You just saved me another day. :) Happy Coding. – Dean Chiu Apr 04 '14 at 03:19