tur11ng
tur11ng

Reputation: 1112

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;

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

    // == 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) {
    super(fm);
    mContext = context;
}

I appreciate any help!

Upvotes: 1

Views: 7150

Answers (4)

Amit Bhati
Amit Bhati

Reputation: 1405

Your FragmentPagerAdapter is of android.support.v4.app.FragmentPagerAdapter either change it to android.app.FragmentPageAdapter

or change this

 mCustomPagerAdapter = new CustomPagerAdapter(getFragmentManager(),this);

to

mCustomPagerAdapter = new CustomPagerAdapter(getSupportFragmentManager(),this);

will solve your problem Cheers :)

Upvotes: 1

Riyaz Parasara
Riyaz Parasara

Reputation: 154

please use getSupportFragmentManager(); to resolve your problems

Upvotes: 0

Sergey Glotov
Sergey Glotov

Reputation: 20346

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

Upvotes: 7

user5827241
user5827241

Reputation:

You need to use getSupportFragmentManager() in your code, not getFragmentManager(). See here why

Upvotes: 1

Related Questions