add() in FragmentTransaction cannot be applied?

android, android-fragments, fragment, java

Solution

Are you using `SupportMapFragment` (from the Support package) and not `MapFragment`

The regular `MapFragment` not work with `SupportFragmentManager`.

See the difference?

private class MyMap1 extends SupportMapFragment {

}

private class MyMap2 extends MapFragment {

}

Problem

Cannot add to fragment transaction due to the following error, how would you go about this? ``` add() in FragmentTransaction cannot be applied to: Expected Parameters: Actual Arguments: int R.id.mapWithOverlay   android.support.v4.app.Fragment _mapFragment  (com.google.android.gms.maps.MapFragment) String "map" ``` Code is as follows: ``` android.support.v4.app.FragmentTransaction fragTx = getSupportFragmentManager().beginTransaction(); if (fragTx != null) { _mapFragment = MapFragment.newInstance(mapOptions); fragTx.add(R.id.mapWithOverlay, _mapFragment, "map"); fragTx.commit(); } else { Toast.makeText(this, "Could not display the map", Toast.LENGTH_SHORT).show(); } ``` Thanks in advance.

Original source

Related problems