Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:29:21+00:00 2026-06-08T18:29:21+00:00

I got a force close when I tried to stop my gsp listener Here’s

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:29:23+00:00Added an answer on June 8, 2026 at 6:29 pm

    I made one service for that. It is easy for get Longitude / Latitude using it.

    1. Copy/paste this class in your project.

    package com.sample;
    import com.sample.globalconstant;

    import android.app.Service;
    import android.content.Context;
    import android.content.Intent;
    import android.location.Location;
    import android.location.LocationManager;
    import android.os.Bundle;
    import android.os.IBinder;
    import android.util.Log;
    import android.widget.Toast;
    
    public class MyServiceGPS extends Service
    {
        private static final String TAG = "BOOMBOOMTESTGPS";
        private LocationManager mLocationManager = null;
        private static final int LOCATION_INTERVAL = 1000;
        private static final float LOCATION_DISTANCE = 10f;
    
        private class LocationListener implements android.location.LocationListener{
            Location mLastLocation;
            public LocationListener(String provider)
            {
                Log.e(TAG, "LocationListener " + provider);
                mLastLocation = new Location(provider);
            }
            public void onLocationChanged(Location location)
            {
                Log.e(TAG, "onLocationChanged: " + location.getLatitude() +"....."+ location.getLongitude());
                globalconstant.lat  = location.getLatitude();
                globalconstant.lon  = location.getLongitude();
                Toast.makeText(getApplicationContext(), location.getLatitude() +"....."+ location.getLongitude(), 1000).show();
                mLastLocation.set(location);
            }
            public void onProviderDisabled(String provider)
            {
                Log.e(TAG, "onProviderDisabled: " + provider);           
            }
            public void onProviderEnabled(String provider)
            {
                Log.e(TAG, "onProviderEnabled: " + provider);
            }
            public void onStatusChanged(String provider, int status, Bundle extras)
            {
                Log.e(TAG, "onStatusChanged: " + provider);
            }
        }
        LocationListener[] mLocationListeners = new LocationListener[] {
                new LocationListener(LocationManager.GPS_PROVIDER),
                new LocationListener(LocationManager.NETWORK_PROVIDER)
        };
        @Override
        public IBinder onBind(Intent arg0)
        {
            return null;
        }
        @Override
        public int onStartCommand(Intent intent, int flags, int startId)
        {
            Log.e(TAG, "onStartCommand");
            super.onStartCommand(intent, flags, startId);      
            return START_STICKY;
        }
        @Override
        public void onCreate()
        {
            Log.e(TAG, "onCreate");
            initializeLocationManager();
            try {
                mLocationManager.requestLocationUpdates(
                        LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                        mLocationListeners[1]);
    
            } catch (java.lang.SecurityException ex) {
                Log.i(TAG, "fail to request location update, ignore", ex);
            } catch (IllegalArgumentException ex) {
                Log.d(TAG, "network provider does not exist, " + ex.getMessage());
            }
            try {
                mLocationManager.requestLocationUpdates(
                        LocationManager.GPS_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
                        mLocationListeners[0]);
            } catch (java.lang.SecurityException ex) {
                Log.i(TAG, "fail to request location update, ignore", ex);
            } catch (IllegalArgumentException ex) {
                Log.d(TAG, "gps provider does not exist " + ex.getMessage());
            }
        }
        @Override
        public void onDestroy()
        {
            Log.e(TAG, "onDestroy");
            super.onDestroy();
            if (mLocationManager != null) {
                for (int i = 0; i < mLocationListeners.length; i++) {
                    try {
                        mLocationManager.removeUpdates(mLocationListeners[i]);
                    } catch (Exception ex) {
                        Log.i(TAG, "fail to remove location listners, ignore", ex);
                    }
                }
            }
        }
        private void initializeLocationManager() {
            Log.e(TAG, "initializeLocationManager");
            if (mLocationManager == null) {
                mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
            }
        }
    }
    
    1. Copy this code in your Activity when you want to start:

      startService(new Intent(this,MyServiceGPS.class));

    2. 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.lon

    3. Add uses-permission in Manifest

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code is causing ANR force close any idea how to improve this code?
I got force close error when opening my install app, herewith i enclosed my
I tried this query on MySQL server (5.1.41)... SELECT max(volume), dateofclose, symbol, volume, close,
I edited the code the way @CommonsWare told me i get force close when
I've got a Prolog program where I'm doing some brute force search on all
Okay, I've got my normal app which is in portrait mode. I can force
Got this error message while trying to load view: The model item passed into
Got a question for some jQuery wizard who might stumble upon this. When I
got a problem, can't get my head around this jquery and would appreciate your
In an Android application, we usually got the "Force Closed" error if we didn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.