title: What can I do instead of waiting for FirebaseDatabase data?
body: <p>i've a problem with the FirebaseDatabase. I want to read the count of childs from a datebase reference. And I want to do this 5 times. So I created 5 SingleEventListeners and set the value, if there's no user for this date. (I hope you understand, what I want to do :D)</p>
  
  <pre><code>while (counter&lt;5) { 
  
              ... We create a new date and username here. We have to do this 5 times
  
              myRef.addListenerForSingleValueEvent(new ValueEventListener() {
                  @Override
                  public void onDataChange(DataSnapshot dataSnapshot) {
                  if (!(dataSnapshot.child(finalDate).hasChild(username)))
                        myRef.child(finalDate).child(username).setValue(true);
                  }
                  @Override
                  public void onCancelled(DatabaseError databaseError) {
                  }
              });
              counter++;
          }
              try { //TODO Synchronisation is not given without that block
                  Thread.sleep(5000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
      }
  
     ...
     ...
     ...
  
  
  
  myRef.child(chosenDate).child(username).addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              participate.setChecked((Boolean) dataSnapshot.getValue());
          }
  </code></pre>
  
  <p>Here we get a Nullpointer Exception, if we don't wait for receiving the date.
  What can I do instead of the use of sleep(), which is really bad :(</p>