JAAAY JAAAY - 2 months ago 28x
Android Question

Android : android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

I'm trying to create an adapter for my fragments but I get this :

Error:(19, 72) error: incompatible types: android.app.FragmentManager cannot be converted to android.support.v4.app.FragmentManager

This is a part of my main activity:

import android.app.Activity;
import android.support.v4.view.ViewPager;
import android.os.Bundle;

public class MainActivity extends Activity {

CustomPagerAdapter mCustomPagerAdapter;
ViewPager mViewPager;

protected void onCreate(Bundle savedInstanceState) {

// == Setting up the ViewPager ==

mCustomPagerAdapter = new CustomPagerAdapter(getFragmentManager(),this); <--- Error is on this line

And this is a part of my customAdapter class :

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

public class CustomPagerAdapter extends FragmentPagerAdapter {

protected Context mContext;

public CustomPagerAdapter(FragmentManager fm, Context context) {
mContext = context;

I appreciate any help!


Your MainActivity should extend FragmentActivity and you should use getSupportFragmentManager() method instead of getFragmentManager().