Java – add() in fragmenttransaction cannot be applied?

Could not be added to the fragment transaction due to the following error. How would you do 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"

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

Thank you in advance

Solution

You are using supportmapfragment (from the support package) instead of mapfragment

Regular mapfragment cannot be used with supportfragment manager

See the difference?

private class MyMap1 extends SupportMapFragment {

}

private class MyMap2 extends MapFragment {

}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>