Q:

error gps requestLocationUpdates android

i've made a class for request location by gps, so after i can use this class on my activity to request longitude and latitude, but i've always this error, i don't understand why...
i've this logcat:
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

for a method that request location by gps. it seems every alright but it doesn't works :(
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

}

}

can you help me please???

A:

Do you ever initialize the locationManager before you call locationManager.requestLocationUpdates?
In the GPS constructor you might want to try
locationManager = (LocationManager)c.getSystemService(Context.LOCATION_SERVICE);

