Shary saleem
Shary saleem

Reputation: 1

Firebase Realtime database correct reference is returning null

I was working on a project, While working on a real-time database the references are correctly configured but retuning null.

DatabaseReference reference = database.getReference(map.get(SessionManager.KEY_CARID)+"/Alert/status");
        //DatabaseReference reference = database.getReference(map.get(SessionManager.KEY_CARID)).child("Alert").child("status");
        reference.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
              if (snapshot.getValue().toString().equalsIgnoreCase("1")) {

In this if statement the function tostring() is not working as its giving null pointer exception. The database structure is as followed.

enter image description here

Upvotes: 0

Views: 62

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80924

Try the following:

DatabaseReference reference = database.getReference("User").child(map.get(SessionManager.KEY_CARID)).child("Alert").child("status");

You need to reference the node User

Upvotes: 1

Related Questions