作業中のアプリケーションの場所を取得しようとしています。ただし、エラーが発生し、最適なプロバイダーを選択しようとすると強制終了します。この問題に関するヘルプをいただければ幸いです...onCreateで何かを宣言して機能させる必要がありますか?次に、エラーが続くコードのスニペットを示します。
public void onStart(){
super.onStart();
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
best = locationManager.getBestProvider(criteria, true);//Selects best location provider given options between GPS and poor man's
locationProvider = locationManager.getProvider(best);
if (locationProvider != null) {
locationManager.requestLocationUpdates(locationProvider.getName(), 60000, 1,
this.locationListenerRecenterMap);
} else {
Log.e(TAG, "NO LOCATION PROVIDER AVAILABLE");
Toast.makeText(this, "The GPS location provider is not available at this time.", Toast.LENGTH_SHORT).show();
finish();
}
GeoPoint location = this.getLastKnownPoint();
this.mapController.animateTo(location);
}
public void onResume(){
super.onResume();
locationManager.requestLocationUpdates(best, 15000, 1, (LocationListener) this);
}
public void onPause(){
locationManager.removeUpdates((LocationListener) this);
}
private GeoPoint getLastKnownPoint(){
GeoPoint lastKnownPoint = GeoUpdateHelper.SCRANTON;
Location lastKnownLocation = this.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(lastKnownLocation != null){
lastKnownPoint = GeoUpdateHelper.getGeoPoint(lastKnownLocation);
}else{
lastKnownPoint = GeoUpdateHelper.SCRANTON;
}
return lastKnownPoint;
}
そしてここにエラーがあります:
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): Caused by: java.lang.IllegalArgumentException: name==null
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): at android.location.LocationManager.getProvider(LocationManager.java:324)
04-16 19:07:25.077: ERROR/AndroidRuntime(4998): at com.example.mapMain.onStart(mapMain.java:76)
編集:これは私のOGドロイドで実行されています。クリックしてアプリケーションのマップ部分を開くと、強制的に閉じる場所が取得されます。