title: How can I check if a value exists already in a Firebase data class Android
body: <p>I want to check if the bus number already exists in the database of Firebase.</p>
  <p>Here's my sample code. I've been searching for the past days but I can't find the right code to do so.</p>
  <pre><code>ref = new Firebase(Config.FIREBASE_URL);
  postRef = ref.child(&quot;BusNumber&quot;);
  
  busNum = edtBus.getText().toString().trim();
  route1 = route.trim();
  seat = edtSeat.getText().toString().trim();
  
  if (!busNum.isEmpty() &amp;&amp; !route1.isEmpty() &amp;&amp; !seat.isEmpty()) {
      postRef.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              if (dataSnapshot.child(busNum).exists()) {
                  edtBus.setError(&quot;Bus number already exists.&quot;);
                  edtBus.setText(&quot;&quot;);
              } else {
                  busNumber = new BusNumber();
                  busNumber.setBusNum(busNum);
                  busNumber.setRoute(route1);
                  busNumber.setNumSeat(seat);
                  postRef.push().setValue(busNumber);
                  edtBus.setText(&quot;&quot;);
                  edtSeat.setText(&quot;&quot;);
                  Toast.makeText(AddBusActivity.this, &quot;Saving successful!&quot;, Toast.LENGTH_SHORT).show();
              }
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
              Toast.makeText(AddBusActivity.this, &quot;Error&quot;, Toast.LENGTH_SHORT).show();
              Toast.makeText(AddBusActivity.this, firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
          }
      });
  
  } else {
      Toast.makeText(AddBusActivity.this, &quot;Please complete the information&quot;, Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  <p>Can somebody help me with this matter? Thanks in advance.
  Whether the if statement is correct or not, also my problem is why does the <code>postRef.addListenerForSingleValueEvent</code>...doesn't work? I tried to test some toast message but the message won't pop out.</p>
  <p><a href="https://i.stack.imgur.com/mF7u1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mF7u1.png" alt="here is my firebase database" /></a></p>