Assigning values to field ("global variable") from external method
<p>I would like to add elements to the three <code>ArrayLists</code> declared in the code bellow but I seem to be having some issues related to variable scope. <strong>Disclaimer:</strong> I'm very new to Java and it could just be that I'm doing something very silly. Also note that I'm using the <a href="https://www.parse.com/docs/android/api/" rel="nofollow">Parse Android API</a>. (I added some comments to the code to better highlight the issue I'm trying to resolve). Thanks!</p>

<pre><code>public class MatchesActivity extends Activity implements OnItemClickListener {

ArrayList&lt;String&gt; titles = new ArrayList&lt;String&gt;();
ArrayList&lt;String&gt; descriptions = new ArrayList&lt;String&gt;();
ArrayList&lt;Bitmap&gt; images = new ArrayList&lt;Bitmap&gt;();
String school;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.matches_layout);

    ParseQuery query = new ParseQuery("Profile");
    query.whereEqualTo("userName", ParseUser.getCurrentUser().getUsername().toString());
    query.getFirstInBackground(new GetCallback() {
        public void done(ParseObject obj, ParseException e) {
            if (e == null) {
                school = obj.getString("school");
                ParseQuery query2 = new ParseQuery("Profile");
                query2.whereEqualTo("school", school);
                query2.findInBackground(new FindCallback() {
                    public void done(List&lt;ParseObject&gt; scoreList, ParseException e) {
                        if (e == null) {
                            // scoreList.size() == 3 here
                            for (int i = 0; i &lt; scoreList.size(); i++){
                                titles.add(scoreList.get(i).getString("fullName"));
                                descriptions.add(scoreList.get(i).getString("sentence"));

                                ParseFile profileImg = (ParseFile) scoreList.get(i).get("pic");
                                try { 
                                    profileImg.getDataInBackground(new GetDataCallback() {
                                        public void done(byte[] data, ParseException e) {
                                            if (e == null) {
                                                Bitmap bMap = BitmapFactory.decodeByteArray(data, 0,data.length);
                                                images.add(bMap);
                                            } else {
                                                Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(),Toast.LENGTH_SHORT).show();
                                            }
                                            // AT THIS POINT THE ARRAYLIST "IMAGES" IS BEING ASSIGNED VALUES
                                        }

                                    });
                                } catch (NullPointerException npe) {
                                    images.add(BitmapFactory.decodeResource(getResources(), R.drawable.ic_prof));
                                }           
                            }           
                            // HERE, THE SIZE OF TITLES AND DESCRIPTION IS 3, HOWEVER, IMAGES HAS NO ELEMENTS (WHEN I EXPECTED IT TO HAVE 3)
                        } else {
                            Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            } else {
                Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    });
    // ALL LISTS ARE EMPTY AT THIS POINT (BUT I WOULD LIKE TO USE THEM HERE)
}
</code></pre>

<p><strong>Problem solved:</strong>
As it was brought up by <em>Yogendra Singh</em> and <em>twaddington</em>, the <code>getDataInBackground</code> method was running as a secondary thread which did not have a chance to finish before I was reaching the specific place in my code where I needed the information being retrieved there. As my ultimate task was to dynamically fill up a listView with information retrieved from my Parse database, I simply decided to follow the hints <a href="http://stackoverflow.com/questions/10084184/how-can-i-inflate-a-listview-dynamically-in-android?lq=1">here</a> and do all that from within the <code>getDataInBackground</code>. That worked! Thanks everyone for the help.</p>
