I got a force close when I tried to stop my gsp listener
Here’s the code:
mlocManager.removeUpdates(mlocListener);
mlocManager = null;
and this:
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
(long) update, 0, mlocListener);
Please help me, I don’t understand why it force closes.
07-30 11:43:39.557: D/AndroidRuntime(1071): Shutting down VM
07-30 11:43:39.557: W/dalvikvm(1071): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-30 11:43:39.575: E/AndroidRuntime(1071): FATAL EXCEPTION: main
07-30 11:43:39.575: E/AndroidRuntime(1071): java.lang.NullPointerException
07-30 11:43:39.575: E/AndroidRuntime(1071): at com.example.anotheractivity.Festivale$1.onClick(Festivale.java:109)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.view.View.performClick(View.java:2485)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.view.View$PerformClick.run(View.java:9080)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.os.Handler.handleCallback(Handler.java:587)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.os.Handler.dispatchMessage(Handler.java:92)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.os.Looper.loop(Looper.java:123)
07-30 11:43:39.575: E/AndroidRuntime(1071): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-30 11:43:39.575: E/AndroidRuntime(1071): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 11:43:39.575: E/AndroidRuntime(1071): at java.lang.reflect.Method.invoke(Method.java:507)
07-30 11:43:39.575: E/AndroidRuntime(1071): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-30 11:43:39.575: E/AndroidRuntime(1071): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-30 11:43:39.575: E/AndroidRuntime(1071): at dalvik.system.NativeStart.main(Native Method)
07-30 11:43:41.565: I/Process(1071): Sending signal. PID: 1071 SIG: 9
I made one service for that. It is easy for get Longitude / Latitude using it.
package com.sample;
import com.sample.globalconstant;
Copy this code in your Activity when you want to start:
startService(new Intent(this,MyServiceGPS.class));
Create one class globalconstant:
public class globalconstant
{
public static double lat, lon;
}
when you want to current latitude and longitude in your project only write this
globalconstant.lat ,globalconstant.lonAdd uses-permission in Manifest