我在这一行得到一个空指针异常:
double latitude = location.getLatitude();
这是导致我出现问题的代码块:
//Get the current location
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
//Zooms into the current location when the activity is started
double latitude = location.getLatitude();
double longitude = location.getLongitude();
初始化 Location 变量和 LocationManager 变量时,如何获得空指针异常?我的代码有什么问题?