how to fix `Type mismatch: cannot convert from and

2019-07-20 12:30发布

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条回答
姐就是有狂的资本
2楼-- · 2019-07-20 13:31

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

查看更多
登录 后发表回答