Thursday, July 7, 2011

Re: [android-developers] Puzzling crash report. Location app doesn't work if the GPS is on

On Thu, Jul 7, 2011 at 9:28 AM, Raghav Sood <raghavsood@gmail.com> wrote:
> I have a app that triangulates the users location and displays it on a map
> without using the GPS. As long as the GPS is off the app does its job
> perfectly. The moment someone turns the GPS on the app force closes and
> gives a NullPointerException on line 37 of MyPositionOverlay which is given
> above. If needed I am willing to share the source code for the entire
> project as there is nothing special in it. It is attached with this mail.
> I would like this group's help on the fact as to why the app force closes
> when the GPS is turned on and how do I fix it. The app does not use the GPS
> at all.

First, your overlay's location data member will be null sometimes, the
way this is written. getLastKnownLocation() can return null at any
time, and in that case, you don't have a Location to work with. You
will need to either add intelligence to the overlay to handle this
case, or not set up the overlay until you have a Location.

Second, you are using GPS, the way this is written. More specifically,
you are using the Criteria system, which will return GPS as a possible
provider. Given your specific Criteria setup, if GPS is available, it
probably is the best provider.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment