Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Null pointer sorting a table column with a row selection listener

JGagnonMay 1 2013 — edited May 1 2013
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2013
Added on May 1 2013
7 comments
943 views