To maintain the state of the button even when leaving and entering the window, the reserved data is called from Firebase and the button is set to Cancel when the reservation has already been made. But I got an error, how do I fix this error?
reference.child("confirm").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(fAuth.getCurrentUser() != null){
if(dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class) != null && !dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class).equals("default")){
book.setText("book");
book.setEnabled(true);
}
if(dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class).equals("0") && dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class) != null){
book.setText("book");
book.setEnabled(true);
}else if(dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class).equals("1") && dataSnapshot.child(fAuth.getCurrentUser().getUid()).child("confirm").getValue(String.class) != null){
book.setText("cancel");
book.setEnabled(true);
}
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
I saw that it was a null problem and tried several things, but couldn't solve it