Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Relating Users in Parse.com Executing a Query

Edit Friends not showing anything

So, when I run the app and press the Edit Friends button it leads me to another activity but nothing is displayed. It's literally all white. No friends, no action bar, nothing. Any idea what could have gone wrong?

EditFriends.java:

package com.marcioporto.android.ribbit;

import android.app.AlertDialog; import android.app.ListActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter;

import com.parse.FindCallback; import com.parse.ParseException; import com.parse.ParseQuery; import com.parse.ParseUser;

import java.util.List;

public class EditFriendsActivity extends ListActivity {

public static final String TAG = EditFriendsActivity.class.getSimpleName();

protected List<ParseUser> mUsers;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_friends);
}

@Override
protected void onResume() {
    super.onResume();

    ParseQuery query = ParseUser.getQuery();
    query.orderByAscending(ParseConstants.KEY_USERNAME);
    // Add search feature later. Look at the Parse documentation regarding this section
    query.setLimit(1000);
    query.findInBackground(new FindCallback() {
        @Override
        public void done(List users, ParseException e) {
            if (e == null) {
                // Success
                mUsers = users;
                String[] usernames = new String[mUsers.size()];
                int i = 0;
                for (ParseUser user : mUsers) {
                    usernames[i] = user.getUsername();
                    i++;
                }
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                        EditFriendsActivity.this,
                        android.R.layout.simple_list_item_checked,
                        usernames);
                setListAdapter(adapter);

            } else {
                Log.e(TAG, e.getMessage());
                AlertDialog.Builder builder = new AlertDialog.Builder(EditFriendsActivity.this);
                builder.setMessage(e.getMessage())
                        .setTitle(R.string.error_title)
                        .setPositiveButton(android.R.string.ok, null);
                AlertDialog dialog = builder.create();
                dialog.show();
            }
        }

        @Override
        public void done(Object o, Throwable throwable) {

        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_edit_friends, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

Layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.marcioporto.android.ribbit.EditFriendsActivity">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

</RelativeLayout>

Jon Kussmann
Jon Kussmann
Courses Plus Student 7,254 Points

Could you post your EditFriends Activity code as well as the corresponding layout?