title: Firebase Database Retrieving Multiple Objects as a List
body: <p>So I'm currently trying to make a Firebase database for an Android Studio app consisting of multiple <code>UserProfile</code> Class Objects, each containing 4 properties, that is username, password, secretQuestion and secretAnswer. I can add these objects to database with each having a unique key, having no problem with that but I need to check every one of them when signing in. I made a retrieving method with ValueEventListener that returns a UserProfile list. When I click sign-in in my login page the method always returns a null list and after restarting the app or playing with some pages, app crashes when I try to sign in. I can't find the problem with the method unfortunately...</p>
  
  <p>Here is my method for getting the data:</p>
  
  <pre><code> public static List&lt;UserProfile&gt; readUserProfile()
  {
      final List&lt;UserProfile&gt; profiles = new ArrayList&lt;UserProfile&gt;();
  
      DatabaseReference getProfile;
      getProfile = CreateProfile1.database.getReference();
      getProfile.child( "UserProfiles").addValueEventListener( new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              Iterable&lt;DataSnapshot&gt; children = dataSnapshot.getChildren();
  
              for ( DataSnapshot child : children )
              {
                  UserProfile aProfile = child.getValue( UserProfile.class);
                  profiles.add( aProfile);
              }
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError)
          {
              Log.e("The read failed: ", databaseError.getMessage());
          }
      });
  
      return profiles;
  }
  </code></pre>
  
  <p>And here is my sign-in checking:</p>
  
  <pre><code>loginProfiles = CreateProfile2.readUserProfile();
  
                  for ( int i = 0; i &lt; loginProfiles.size(); i++ )
                  {
                      if ( loginProfiles.get( i).getUsername().equals( usernameField.getText().toString() ) &amp;&amp;
                              loginProfiles.get( i).getPassword().equals( passwordField.getText().toString() ) )
                      {
                          Intent goToMainPage;
                          goToMainPage = new Intent(LoginPage.this, MainMenu.class);
  
                          startActivity(goToMainPage);
                      }
                  }
  </code></pre>