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

那年仲夏 提交于 2019-12-13 16:09:40

问题


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?


回答1:


Replace getFragmentManager() with getSupportFragmentManager(), and make sure your class is a subclass of FragmentActivity.



来源:https://stackoverflow.com/questions/23212994/how-to-fix-type-mismatch-cannot-convert-from-android-app-fragmentmanager-to-an

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!