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

"Unfortunately, Ribbit has stopped" error AFTER IMPLEMENTING INBOX AND FRIENDS FRAGMENTS

This is what logcat says...

07-24 01:41:53.108: E/AndroidRuntime(1174): FATAL EXCEPTION: main 07-24 01:41:53.108: E/AndroidRuntime(1174): Process: com.jared.ribbit, PID: 1174 07-24 01:41:53.108: E/AndroidRuntime(1174): java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.ListFragment.ensureList(ListFragment.java:344) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.ListFragment.onViewCreated(ListFragment.java:145) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.view.ViewPager.populate(ViewPager.java:914) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.View.measure(View.java:16497) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.View.measure(View.java:16497) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 07-24 01:41:53.108: E/AndroidRuntime(1174): at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.View.measure(View.java:16497) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 07-24 01:41:53.108: E/AndroidRuntime(1174): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.View.measure(View.java:16497) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.Choreographer.doCallbacks(Choreographer.java:574) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.Choreographer.doFrame(Choreographer.java:544) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.os.Handler.handleCallback(Handler.java:733) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.os.Handler.dispatchMessage(Handler.java:95) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.os.Looper.loop(Looper.java:136) 07-24 01:41:53.108: E/AndroidRuntime(1174): at android.app.ActivityThread.main(ActivityThread.java:5017) 07-24 01:41:53.108: E/AndroidRuntime(1174): at java.lang.reflect.Method.invokeNative(Native Method) 07-24 01:41:53.108: E/AndroidRuntime(1174): at java.lang.reflect.Method.invoke(Method.java:515) 07-24 01:41:53.108: E/AndroidRuntime(1174): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 07-24 01:41:53.108: E/AndroidRuntime(1174): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 07-24 01:41:53.108: E/AndroidRuntime(1174): at dalvik.system.NativeStart.main(Native Method) 07-24 01:41:53.648: D/dalvikvm(1174): GC_FOR_ALLOC freed 369K, 9% free 4487K/4924K, paused 100ms, total 110ms 07-24 01:41:59.288: I/Process(1174): Sending signal. PID: 1174 SIG: 9

3 Answers

In your fragment_inbox.xml file, do you have the lines:

<ListView
    android:id="@android:id/list"
    ... >
</ListView>

That seems to be something to do with the error - I'm just not sure how you can get as far as you have with the error existing! I'm unsure how it'll build, never mind run!

We'll get there!

Steve.

There should be an identical line in fragment_friend.xml too.

It's fixed! Thank you! For some reason it said android:id="@+id/list" instead.

It's fixed! Thank you! For some reason it said android:id="@+id/list" instead.

Glad that worked!! :)

Just got time for a quick glance at this ... I noticed:

Your content must have a ListView whose id attribute is 'android.R.id.list'

That may help locate where the issue is ... check your graphical layout and xml for the correct id?

Although it is looking for android.R ... Try Project | Clean ... that may help distill the error down.

Calvin Nix
Calvin Nix
43,828 Points

Hey Jared,

As Steve advised, try to clean your project to see if the error gets resolved.

If you are still receiving the same error message could you please provide the code of the class that you changed to implement the Friends and Inbox Fragments?

Cleaning it didn't solve it. This is the mainActivity, Friends Fragment, InboxFragment, and SectionsPagerAdapter code.

MAIN ACTIVITY <code> package com.jared.ribbit;

import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.util.Log; import android.view.Menu; import android.view.MenuItem;

import com.parse.ParseAnalytics; import com.parse.ParseUser;

public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {

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

/**
 * The {@link android.support.v4.view.PagerAdapter} that will provide
 * fragments for each of the sections. We use a
 * {@link FragmentPagerAdapter} derivative, which will keep every
 * loaded fragment in memory. If this becomes too memory intensive, it
 * may be best to switch to a
 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
 */
SectionsPagerAdapter mSectionsPagerAdapter;

/**
 * The {@link ViewPager} that will host the section contents.
 */
ViewPager mViewPager;

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

    ParseAnalytics.trackAppOpened(getIntent());

    ParseUser currentUser = ParseUser.getCurrentUser();

    if(currentUser == null){
        navigateToLogin();
    }
    else{
        Log.i(TAG, currentUser.getUsername());
    }

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter. Also specify this Activity object, which implements
        // the TabListener interface, as the callback (listener) for when
        // this tab is selected.
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}


private void navigateToLogin() {
    Intent intent = new Intent(this, LoginActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {
        ParseUser.logOut();
        navigateToLogin();
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
    // When the given tab is selected, switch to the corresponding page in
    // the ViewPager.
    mViewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}

@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}

}

</code>

INBOX FRAGMENT <code> package com.jared.ribbit;

import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;

public class InboxFragment extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_inbox, container, false); return rootView; }

}

</code>

Friends Fragment <code> package com.jared.ribbit;

import android.os.Bundle; import android.support.v4.app.ListFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;

public class FriendsFragment extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_friends, container, false); return rootView; }

}

</code>

SectionsPagerAdapter <code> package com.jared.ribbit;

import java.util.Locale;

import android.content.Context; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter;

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    protected Context mContext;

    public SectionsPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).

        switch(position){
        case 0:
            return new InboxFragment();
        case 1:
            return new FriendsFragment();
        }
        return null;
    }

    @Override
    public int getCount() {
        // Show 2 total pages.
        return 2;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        Locale l = Locale.getDefault();
        switch (position) {
            case 0:
                return mContext.getString(R.string.title_section1).toUpperCase(l);
            case 1:
                return mContext.getString(R.string.title_section2).toUpperCase(l);
        }
        return null;
    }
}

</code>