I'm getting an NullPointerException with the following code:
private ProjectionProxy proxy = new ProjectionProxy();
private GoogleMap mMap = null;
private Context context = this;
@Override
protected void onCreate(Bundle load) {
super.onCreate(load);
setContentView(R.layout.fragment_ride_tracking);
//mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.myMapView)).getMap();
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setMyLocationEnabled(true);
//SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.myMapView);
//mMap = mapFragment.getMap();
Log.e("RideTracking", "Google Map VALUE:"+mMap);
if (mMap != null) {
proxy.setProjection(mMap.getProjection());
}
The line where the NullPointerException is happening is this line of code:
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
I'm not initializing my mMap variable to null. What is my issue here?
MainActivity.xml :
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
MainActivity.java :
private GoogleMap googleMap;
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
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