Title

Sunday, 18 January 2015

how to fix `Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager` error in android?


I am getting the following error

Type mismatch: cannot convert from android.app.FragmentManager to android.support.v4.app.FragmentManager

for the following line

FragmentManager frgManager = getFragmentManager(); frgManager.beginTransaction().replace(R.id.content_frame, fragment).commit();

I have the following imports in my class

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

How to fix the error?

Answer

Replace getFragmentManager() with getSupportFragmentManager().

Answer2

Replace these imports

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

with these

import android.app.Fragment;  import android.app.FragmentManager;

No comments:

Post a Comment