Skip to content Skip to sidebar Skip to footer

Unable To Detect If Datasnapshot Is Null Or Not Under 'addchildeventlistener()`

I have set up a Firebase database for my app & it looks like this: app -category -subCategory -subSubCategory I have an addChildEventListener() set up like this: mDataba

Solution 1:

The dataSnapshot object itself will never be null. But you can ask if it's got any data, by calling dataSnapshot.exists(). So:

public void onDataChange(DataSnapshot dataSnapshot) {
    if (dataSnapshot.exists()) {
        Log.d("dataSnapshot", "AVAILABLE");
    } else {
        Log.d("dataSnapshot", "NO DATA");
    }
}

Post a Comment for "Unable To Detect If Datasnapshot Is Null Or Not Under 'addchildeventlistener()`"