gps で場所をリクエストするためのクラスを作成したので、このクラスをアクティビティで使用して経度と緯度をリクエストできますが、常にこのエラーが発生し、理由がわかりません...
私はこのログキャットを持っています:
07-10 17:13:49.645: E/AndroidRuntime(10269): FATAL EXCEPTION: main
07-10 17:13:49.645: E/AndroidRuntime(10269): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.provags/com.example.provags.MainActivity}: java.lang.NullPointerException
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.os.Handler.dispatchMessage(Handler.java:99)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.os.Looper.loop(Looper.java:137)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-10 17:13:49.645: E/AndroidRuntime(10269): at java.lang.reflect.Method.invokeNative(Native Method)
07-10 17:13:49.645: E/AndroidRuntime(10269): at java.lang.reflect.Method.invoke(Method.java:511)
07-10 17:13:49.645: E/AndroidRuntime(10269): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
07-10 17:13:49.645: E/AndroidRuntime(10269): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
07-10 17:13:49.645: E/AndroidRuntime(10269): at dalvik.system.NativeStart.main(Native Method)
07-10 17:13:49.645: E/AndroidRuntime(10269): Caused by: java.lang.NullPointerException
07-10 17:13:49.645: E/AndroidRuntime(10269): at com.example.provags.Gps.getLocation(Gps.java:19)
07-10 17:13:49.645: E/AndroidRuntime(10269): at com.example.provags.Gps.<init>(Gps.java:16)
07-10 17:13:49.645: E/AndroidRuntime(10269): at com.example.provags.MainActivity.onCreate(MainActivity.java:16)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.Activity.performCreate(Activity.java:4465)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-10 17:13:49.645: E/AndroidRuntime(10269): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-10 17:13:49.645: E/AndroidRuntime(10269): ... 11 more
gps で位置情報をリクエストするメソッドの場合。すべて問題ないようですが、機能しません:(
public class Gps implements LocationListener {
Context myContext;
Location posizione;
double latitudine,longitudine;
LocationManager locationManager;
public Gps(Context c){
myContext=c;
getLocation();
}
public Location getLocation(){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
if(locationManager!=null){
posizione=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if(posizione!=null){
latitudine=posizione.getLatitude();
longitudine=posizione.getLongitude();
}
}
return posizione;
}
public double latitudine(){
if(posizione!=null){
latitudine=posizione.getLatitude();
}
return latitudine;
}
public double longitudine(){
if(posizione!=null){
longitudine=posizione.getLongitude();
}
return longitudine;
}
public void stopGps(){
if (locationManager!=null){
locationManager.removeUpdates(Gps.this);
}
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
私を助けてくれますか?