我正在使用此代码设置地图的中心。
mapController.setCenter(new GeoPoint((int)(location.getLatitude()*1E6), (int) (location.getLongitude()*1E6)));
其中location被定义为
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
我使用此代码获得空指针异常。我做错了什么?
答案 0 :(得分:1)
如果当前禁用了提供程序,则返回null。
您可能从locationManager.getLastKnownLocation(provider)获得null响应;