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

Error in MainActivity.java

I have downloaded the latest ADK and created the Ribbit project and removed the fragment_main_list.xml item.

However the mViewPager = (ViewPager) findViewById(R.id.pager); line gives me an error.

How can I fix this error?

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

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

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

4 Answers

I would double check to make sure you have the correct import. Also, I'd double check the xml file to make sure you have an id of 'pager'

Do you have a closing brace for the onCreate method?

Mark,

Thank you for you quick response.

Below is the total onCreate method. Yes I do have a closing brace.

Dan

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

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

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

}

Thank you again Mark!

Actually, I got frustrated and found and older version of Eclipse in my backup files.

Am reloading that version, which did not create a fragment_main portion.

Dan