Cannot resolve method 'getSupportFragmentManager ( )' inside Fragment
Solution 1
Inside a Fragment
subclass you have to use getFragmentManager
in place of getSupportFragmentManager
. You will get the support one if the import are from the support library.
Solution 2
For my case, I made sure that Fragment class is imported from
android.support.v4.app.Fragment
Not from
android.app.Fragment
Then I have used
getActivity().getSupportFragmentManager();
And now its working. If I use activity instance which I got in onAttach() is not working also.
Solution 3
Extends FragmentActivity instead of Activity
Solution 4
Use getActivity().getSupportFragmentManager()
Solution 5
Replace getSupportFragmentManager()
with getFragmentManager()
if you are working in api 21.
OR
If your app supports versions of Android older than 3.0, be sure you've set up your Android project with the support library as described in Setting Up a Project to Use a Library and use getSupportFragmentManager()
this time.
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I found the message Cannot resolve method 'getSupportFragmentManager ( )' I want to fragment as activity. because I want to use Maps on the tabs swipe.
public class PETAcikarangsukatani extends Fragment { Context context; private static final LatLng SUKATANI = new LatLng(-6.171327, 107.178108); private static final LatLng WRPOJOK = new LatLng(-6.222411, 107.162158); private static final LatLng PILAR = new LatLng(-6.257033, 107.156472); private static final LatLng CIKARANG = new LatLng(-6.256073, 107.143984); GoogleMap googleMap; final String TAG = "PathGoogleMapActivity"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_path_google_map, container, false); context = rootView.getContext(); SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager() .findFragmentById(R.id.map); googleMap = fm.getMap();