title: Cannot return value from a method with void result type
body: <p>I'm trying to get a specific value from Firebase database, and I did it before, but now when I'm trying something a bit different, it says "Cannot return value from a method with void result type".</p>
  
  <p>I can guess that I'm missing some programming rules because I'm a new Java programmer.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public int getVotesForEvent(final String event_title) {
      firebaseRef.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              if (dataSnapshot.child("Votes").exists()) {
  
                  for (DataSnapshot event : dataSnapshot.child("Votes").getChildren()) {
                      String event_title2 = event.getKey();
                      if (event_title2.equals(event_title)) {
                          int count=Integer.parseInt(event.getValue().toString());
                          return count;
  
                      }
  
  
                  }
  
              }
              else {
                  int count = 0 ;
                  return count;
              }
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  }
  </code></pre>
  
  <p>The error appears where I'm trying to return count.</p>
  
  <p>After reading comments, this is my code and now the method doesn't effect the declared variable count, it keeps 0:</p>
  
  <pre><code>  int count=0;
  public int getVotesForEvent(final String event_title) {
  
      firebaseRef.addValueEventListener(new ValueEventListener() {
  
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
  
              if (dataSnapshot.child("Votes").exists()) {
                  boolean flag=false;
                  for (DataSnapshot event : dataSnapshot.child("Votes").getChildren()) {
                      String event_title2 = event.getKey();
                      if (event_title2.equals(event_title)) {
                          flag=true;
                          Toast.makeText(EventInfo.this, ""+Integer.parseInt(event.child("event_votes").getValue().toString()), Toast.LENGTH_SHORT).show();
                          count=Integer.parseInt(event.child("event_votes").getValue().toString());
  
  
                      }
  
  
                  }
                  if(flag!=true)
                  {
                      count=0;
                  }
  
              }
              else
              {
                  count=0;
              }
  
          }
  
  
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
  
      });
      return count;
  
  }
  </code></pre>
  
  <p>What am I doing wrong now?</p>