我收到带有以下代码的 NullPointerException:
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());
}
NullPointerException 发生的行是这行代码:
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
我没有将我的 mMap 变量初始化为 null。我的问题是什么?