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();
Inside a
Fragment
subclass you have to usegetFragmentManager
in place ofgetSupportFragmentManager
. You will get the support one if the import are from the support library.If you're getting "Cannot resolve method getSupportFragmentManager()", try using
It works for me when dealing with DialogFragments in android
I tried all above, but none working
Finally tried this my own
and is working .. :)
If you're instantiating an
android.support.v4.app.Fragment
class, the you have to callgetActivity().getSupportFragmentManager()
to get rid of the cannot-resolve problem. However the official Android docs on Fragment by Google tends to over look this simple problem and they still document it without thegetActivity()
prefix.As per the documentation, getSupportFragmentManager() is present only inside AppCompatActivity class. It is not present inside Activity class. So make sure your class extends AppCompatActivity class.
Use
getActivity().getSupportFragmentManager()