So, in my initialize method, I am trying to bind certain buttons so that they are only enabled when an item is selected. But I keep getting a null pointer exception when I do that. I also get null pointer exception on the line in my start method
photos.setItems(FXCollections.observableArrayList(currAlbum.getPhotos()));
Granted at the start of this application, photos would be empty but shouldn't this just create an empty listview? Is there a problem with creating a listview of a photo object?
public class albumController {
@FXML AnchorPane root;
@FXML Label albumNameLabel, albumNameBackgrounLabel, photoLibraryLabel, captionInstruction, captionLabel, tagsInstruction, tagLabel, tagInstruction, valueInstruction, dateInstruction, dateLabel, instructionLabel;
@FXML ListView<Photo> photos;
@FXML Button displayButton, backButton, logOutButton, quitButton, renameButton, createTagButton,addTagButton, deleteTagButton, addPhotoButton, deletePhotoButton, copyMoveButton, moveButton;
@FXML TextField renameField, createTag, createTagValue, addTagValue;
@FXML ChoiceBox<String> addTag, deleteTag, deleteTagValue;
User user;
UserList userList;
Album currAlbum;
/**
* Initializes the user, his albums, and his photos
* @param user Current user logged in
* @param currAlbum Current album user is viewing
*/
public void start(Album currAlbum) {
this.currAlbum=currAlbum;
albumNameLabel.setText(currAlbum.getName());
/*
photos.setCellFactory(new Callback<ListView<Photo>, ListCell<Photo>>(){
@Override
public ListCell<Photo> call(ListView<Photo> p) {
return new PhotoCell();
}
});
*/
photos.setItems(FXCollections.observableArrayList(currAlbum.getPhotos()));
//photos.getSelectionModel().select(0);
/*
* if there is at least one photo, select it and fill in the caption and tag labels
*/
//initialize tag presets
addTag.setItems(FXCollections.observableArrayList(user.getTagNames()));
}
public void initialize() {
copyMoveButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
moveButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
deletePhotoButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
renameButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
createTagButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
addTagButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
deleteTagButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
displayButton.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
createTag.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
createTagValue.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
addTag.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
addTagValue.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
deleteTag.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
deleteTagValue.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
renameField.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
renameField.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
renameField.disableProperty().bind(Bindings.isNull(photos.getSelectionModel().selectedItemProperty()));
/*
captionLabel.textProperty().bind(Bindings.createStringBinding(() -> {
var selectedItem = photos.getSelectionModel().getSelectedItem() ;
if (selectedItem == null) {
captionLabel.setText("");
}
else {
captionLabel.setText(selectedItem.getCaption());
}
}),
photos.getSelectionModel().selectedItemProperty()
);
*/
}