Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: required: android:support.v4.FragmentManager, found: android.app.FragmentManager

 FragmentManager manager = getFragmentManager();

It is giving the error

required : android:support.v4.FragmentManager
found: android.app.FragmentManager

I am using API 15

like image 787
Bandaru Yeswanth Kumar Avatar asked Dec 17 '25 21:12

Bandaru Yeswanth Kumar


2 Answers

Use getSupportFragmentManager(), or change the import for FragmentManager from what you have (android.support.v4.app.FragmentManager) to android.app.FragmentManager.

You need to consistently use either the native classes or the backport. You cannot mix and match.

like image 149
CommonsWare Avatar answered Dec 20 '25 12:12

CommonsWare


add these two import

  import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentTransaction;

for example

   FragmentA fragmentA = new FragmentA();
    FragmentManager fragmentManager =getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(R.id.id_parent_fragment,fragmentA);
    fragmentTransaction.commit();

consider FragementA is the fragment that you want to insert in the activity which in this case is the container in the activity id_parent_fragment

like image 26
khaleader Avatar answered Dec 20 '25 12:12

khaleader



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!