-1

I want to populate the main window's listview whilst the child modal window is in focus. I'm getting a non-static method cannot be referenced from a static context error.

I have this so far...

EDIT: Made methods static, now have null-pointer exception. The array APPLICABLE_CLAUSES definitely has contents.

-----------------NewProject.java child modal window---------------
@FXML protected void createNewProject(ActionEvent event) {
//other code
MainController.displayApplicableClauses();//ERROR OCCURS HERE
}
----------MainController.java parent window-------------
public class MainController {

    @FXML private static ListView addListView;
    public static void displayApplicableClauses() {

       // Populate the ListView.
        addListView.setItems(FXCollections.observableArrayList(APPLICABLE_CLAUSES));   
    }
}
Adam Bardon
  • 3,829
  • 7
  • 38
  • 73
user1406186
  • 940
  • 3
  • 16
  • 28
  • Why are you making everything static anyway? It makes no sense to have static members in a controller. Also see http://stackoverflow.com/questions/23105433/javafx-8-compatibility-issues-fxml-static-fields/23109125#23109125 – James_D Feb 25 '16 at 15:44

1 Answers1

0

The reason your getting the exceptions are that static methods are executed when the class is first loaded. No initiaization has taken place, so your object references are not pointing at anything. Hence the null pointer exception. If you want to be able to access methods statically, you won't be able to have the dynamic content that I'm guessing you want.

tove
  • 35
  • 2
  • 11
  • That makes sense, how would I populate the listview when the child window is closed then? I see other close source programs do this – user1406186 Feb 25 '16 at 13:49