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 Displaying Our List of Friends

Yongshuo Wang
Yongshuo Wang
5,500 Points

My code cannot run.

I got the following exception when I run the code.

03-17 10:19:26.719 1955-1955/me.yongshuo.ribbit E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: me.yongshuo.ribbit, PID: 1955 java.lang.IllegalStateException: Content view not yet created at android.support.v4.app.ListFragment.ensureList(ListFragment.java:328) at android.support.v4.app.ListFragment.getListView(ListFragment.java:222) at me.yongshuo.ribbit.FriendsFragment$1.done(FriendsFragment.java:55) at me.yongshuo.ribbit.FriendsFragment$1.done(FriendsFragment.java:42) at com.parse.Parse$5$1.run(Parse.java:924) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

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

        mCurrentUser = ParseUser.getCurrentUser();

        mFriendsRelation = mCurrentUser.getRelation(ParseConstances.KEY_FRIENDS_RELATION);

        mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
            @Override
            public void done(List<ParseUser> parseUsers, ParseException e) {
                if (e == null){
                    mFriends = parseUsers;

                    String[] usernames = new String[mFriends.size()];

                    int i = 0;

                    for (ParseUser user : mFriends){
                        usernames[i] = user.getUsername();
                        i++;
                    }
                    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getListView().getContext(),
                            android.R.layout.simple_list_item_1,usernames);

                    setListAdapter(adapter);
                }else{
                    AlertDialog.Builder builder = new AlertDialog.Builder(getListView().getContext());

                    builder.setMessage(e.getMessage())
                            .setTitle(R.string.get_friend_error)
                            .setPositiveButton(android.R.string.ok, null);
                    AlertDialog dialog = builder.create();

                    dialog.show();
                    Log.e(TAG, e.getMessage());
                }
            }
        });
    }

1 Answer

Yongshuo, I think a lot of times you have to use the auto-complete feature when typing out the code, I found that when I didn't use auto-complete Android Studio would not import the required classes. Also some times the classes it suggests to import are not always the first in a list of multiple classes with the same name. I don't know if this will help but it has helped me in the past.

If you look at the errors that are being given you can google what they are. Also, I see content view not created. Did you perhaps miss a step in the setup of the views? Good luck!