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 Using Fragments for Tabs Modifying Fragments from the Template

SectionsPagerAdapter.java error in Android Studio

I have made all the changes in the Teacher's Notes but I still get an error in SectionsPagerAdapter.java. Here is the code in the file:

package com.example.zacharygassem.blinker;

/**
 * Created by Zachary Gassem on 27/09/2014.
 */

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

/**
 * A {@link android.support.v13.app.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).
        return MainActivity.PlaceholderFragment.newInstance(position + 1);
    }

    @Override
    public int getCount() {
        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;
    }
}

```Android

4 Answers

Never mind I solved it

Jaroslav Vankat
Jaroslav Vankat
12,054 Points

How did you solve this? Edit: Nevermind I solved it (for other users - the problem was the library in MainActivity, you need to change this line

import android.support.v4.app.Fragment;

to

import android.support.v4.app.Fragment;

Thank you so much!

Thank you so much!

Darrius Taylor
Darrius Taylor
1,934 Points

What is your error or what line is the error on?

I get an error on line 31 and it says "Incompatible types: required: android.support.v4.app.Fragment found: mypackagename.PlaceholderFragment"

I get an error on line 31 and it says "Incompatible types: required: android.support.v4.app.Fragment found: mypackagename.PlaceholderFragment"