0

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

  • 1
    We can't solve it either, because we can't see what this code is doing at runtime, and we don't know the contents of your database. You'll have to do some debugging to figure out which method returned a null object and check it before calling methods on it. I suggest starting with the calls to getValue. – Doug Stevenson Apr 04 '22 at 19:38
  • You need to post the actual error from the stacktrace, because that tells you where you're running into the null, and gives some clues about why it's happening – cactustictacs Apr 05 '22 at 00:16

0 Answers0