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 995563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:44:34+00:00 2026-05-16T06:44:34+00:00

I have an activity that implements LocationListener in my application and my onLocationChanged method

  • 0

I have an activity that implements LocationListener in my application and my onLocationChanged method has been working perfectly up until recently. For some reason the Location object being passed into the method is null. My question is, why is it null? Does it pass in a null object if it cannot acquire a location?

My GPS is on and I have it set to pull a location from the GPS, and I know my GPS can get a fix on me as I used Maps and had it locate me.

Also, I have the permission for my app set as:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

I don’t believe permissions is the issue though, as my activity was working beforehand and I have not altered the permissions since then.

Here is the code that determines the provider of the location object:

String locationProvider = this.mLocationManager.getBestProvider(mLocationCriteria, true);
this.onLocationChanged(this.mLocationManager.getLastKnownLocation(locationProvider));

Here is the LogCat output of the error:

08-08 18:25:26.310: ERROR/MapActivity(6447): Couldn't get connection factory client
08-08 18:26:18.771: ERROR/AndroidRuntime(6447): Uncaught handler: thread main exiting due to uncaught exception
08-08 18:26:18.880: ERROR/AndroidRuntime(6447): java.lang.IllegalStateException: Could not execute method of the activity
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.View$1.onClick(View.java:2031)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.View.performClick(View.java:2364)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.View.onTouchEvent(View.java:4179)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.View.dispatchTouchEvent(View.java:3709)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.os.Looper.loop(Looper.java:123)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.app.ActivityThread.main(ActivityThread.java:4363)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at java.lang.reflect.Method.invokeNative(Native Method)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at java.lang.reflect.Method.invoke(Method.java:521)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at dalvik.system.NativeStart.main(Native Method)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447): Caused by: java.lang.reflect.InvocationTargetException
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.proto.screens.MyMapActivity.onLocateUserClick(MyMapActivity.java:147)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at java.lang.reflect.Method.invokeNative(Native Method)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at java.lang.reflect.Method.invoke(Method.java:521)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at android.view.View$1.onClick(View.java:2026)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     ... 21 more
08-08 18:26:18.880: ERROR/AndroidRuntime(6447): Caused by: java.lang.NullPointerException
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     at com.proto.screens.MyMapActivity.onLocationChanged(MyMapActivity.java:135)
08-08 18:26:18.880: ERROR/AndroidRuntime(6447):     ... 25 more

[UPDATE] I have tested the same code on another device (an HTC MyTouch 3G to be precise) and it works flawlessly with the GPS, however on my Motorola Droid it crashes.

  • 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-05-16T06:44:34+00:00Added an answer on May 16, 2026 at 6:44 am

    I have fixed the problem, though I’m not sure why this worked.

    What I did is I set my activity to request location updates from the best location provider (in this case the GPS) and set it to trigger my function onces it has a location accurate down to 50 meters. What I was doing before was just attempting to retrieve the last known location, but now I have it set to wait until the GPS can get a fix.

    Perhaps it wasn’t storing my last known location and thus was returning null.

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

Sidebar

Related Questions

So basically, I have an Activity that implements an interface and has several inherited
I have an application wherein I have a service class that implements a locationlistener.
I have two activities, A and B. Activity A implements a LocationListener that periodically
I have an activity that shows some TextView s and EditText s, as well
I have an activity that some times OutOfMemory exception occurs in some parts of
I have an activity that launches another activity with startActivityForResult method. I would like
I have an activity that runs some ASCII control over a network port to
I have a simple (?) Android application that begins with an Activity (First Activity)
I have an activity that load sharedPreference from another activity and put some data
Ok so i have an activity A that has a fragment A, and an

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.