Cannot resolve method 'getSupportFragmentManager ( )' inside Fragment

Irwans picture Irwans · Dec 11, 2014 · Viewed 114.9k times · Source

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();

Answer

Blackbelt picture Blackbelt · Dec 11, 2014

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.