Been having trouble with my application that finds a users location and displays it to the screen. The application just crashes both on the emulator and on my phone whilst debugging.
logcat gives me this:
03-26 15:41:37.958: ERROR/AndroidRuntime(871): Uncaught handler: thread main exiting due to uncaught exception
03-26 15:41:37.988: ERROR/AndroidRuntime(871): java.lang.NullPointerException
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at com.finalyear.fitnessapp.fitnessMapActivity$GeoUpdateHandler.onLocationChanged(fitnessMapActivity.java:62)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:179)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:112)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:128)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.os.Handler.dispatchMessage(Handler.java:99)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.os.Looper.loop(Looper.java:123)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at android.app.ActivityThread.main(ActivityThread.java:4603)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at java.lang.reflect.Method.invokeNative(Native Method)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at java.lang.reflect.Method.invoke(Method.java:521)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-26 15:41:37.988: ERROR/AndroidRuntime(871): at dalvik.system.NativeStart.main(Native Method)
03-26 15:41:40.018: ERROR/ActivityManager(87): fail to set top app changed!
03-26 15:41:51.238: ERROR/MapActivity(933): Couldn't get connection factory client
My code is:
public class GeoUpdateHandler implements LocationListener {
@Override
public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
mapController.animateTo(point);
mapController.setCenter(point);
}
Any help would be great been stuck on this for a few weeks now.
My first thought is that your location is being passed in as null, which you could check for.
Why that’s happening? Did you set the location request in your manifest?
Check this thread:
Location Null Pointer