I am trying to implement Google Map in android using Google API, but I am getting the error
The method getFragmentManager() is undefined for the type MainActivity
the whole MainActivity
code is as follows:
public class MainActivity extends Activity {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
Fragments were available from Honey Comb onwards and hence your target API shall >= 11
If you want to use fragments to older versions of android you shall use android support v7 library. And in that case your MainActivity shall extend ActionBarActivity, instead of Activity.
If you are using android support v4, your MainActivity shall extend FragmentActivity and you will need to call getSupportFragmentManager() instead of getFragmentManager()
I hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With