I have a situation where I have attached a change listener to a property that is bound to the selected row of a TableView. For example:
In JavaFX "view" class:
// Bind model content to table.
table.itemsProperty().bind(model.tableContentProperty());
// Bind selected table row to "selected row" property.
model.selectedRowProperty().bind(table.getSelectionModel().selectedItemProperty());
In "view" model class:
selectedRowProperty.addListener(new ChangeListener<MyType>() {
public void changed(ObservableValue<? extends MyType> arg0, MyType arg1, MyType arg2) {
... do something using passed arguments ...
}
});
I'm doing this so that when a user selects a row in the table, I have the information needed for the row that's selected and can then update the contents of another table with "child" data associated with the selected row.
This appeared to be working well up to this point, until I experimented and decided to sort the table column (the table has only the one column, but that should be irrelevant). As soon as I do this, I get a null pointer exception in the change listener. If I don't have a selected row in the table, sorting works fine and throws no exception; this only seems to occur with a row selected and a change listener attached that attempts to do something with the arguments passed to the
changed() method.
Any ideas as to what is happening here? Any suggestions about how to get around this problem?