I am attempting to write a listener for when a new item is selected on a ListView Node. But the problem is I get a NPE when I run the application. From looking at it I am assuming that this may be being thrown because the list is empty upon run time, but I have no clue how to fix it.
Update 1: From further investigation, with a btn action listener I am writing. When I tried to access the selected item, I was thrown a null pointer exception. Work around was wrapping it with a try/catch, which ultimately fixed it. Will try something similar with viewList and see if it will work
Update 2: try/catch(NPE) workaround worked for the viewList action Listener
Code at Line 186: ListView.getSelectionModel().selectedItemProperty().addListener(new...
listView = new ListView<BusinessCard>();
observableList = FXCollections.observableList(cardModel.getCards());
//cardModel.getCards() -> ArrayList<BusinessCards>
// ListView Listener, changes text fields for the selected B.C in ViewLsit
listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<BusinessCard>() {
@Override
public void changed(ObservableValue<? extends BusinessCard> arg0, BusinessCard oldval,BusinessCard newVal) {
if(newVal != null) setDataFields(newVal.getUI());
}
});