How can i check if the node HighExpense exist or not in my Firebase?

Vicky Gupta :
DatabaseReference dr = FirebaseDatabase.getInstance().getReference().child("HighExpense");

Can anyone suggest a solution? Thanks in advance.

Alex Mamo :

The simplest solution for that would be to attach a listener and use DataSnapshot`s exists() method, like in the following lines of code:

dr.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        if (dataSnapshot.exists()) {
            //Get data from the dataSnapshot object
        } else {
            //Data is not present
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
    }
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=344708&siteId=1