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

StackOverflow https://stackoverflow.com/questions/23212994

  •  07-07-2023
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top