0

I have a query like given below,

Query query = mDbRefusers_chat.child("chatId");

Now I want to check if that query exists. that is I want to check if a child with the name "chatId" exists. How to do that ?

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
neab
  • 91
  • 1
  • 3
  • 10
  • actually that has not solved the problem. Its giving me the following exception.' java.lang.RuntimeException: Unable to start activity ComponentInfo{com.iworld.daxi/com.iworld.daxi.UserChatActivity}: java.lang.RuntimeException: Failed to call observer method' @Peter Haddad – neab Mar 08 '18 at 06:31

1 Answers1

2

Try this:

DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("chat_id");
ref.addValueEventListener(new ValueEventListener(){
 @Override
public void onDataChange(DataSnapshot dataSnapshot){
  if(dataSnapshot.exist() {

      }
    }
  @Override
public void onCancelled(DatabaseError databaseError) {

     }
 });

using dataSnapshot.exist() it will check if the child chat_id exists in the database.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134