Skip to content Skip to sidebar Skip to footer

Android Mystery Nullpointerexception Getting Last Known Location

I'm getting a NullPointerException in one of my applications. I had thought I was accounting for all places in this piece of code for Null references, but it seems that I may have

Solution 1:

Without too much analysis on your code, could it be a permissions issue? Maybe your app isn't allowed to use GPS data, which is causing an unexpected error?

-Woody

Solution 2:

I didnt see where you register for location updates? Maybe that is what you are missing here.

Solution 3:

I had accidentally removed a line from my code prior to posting it as I had thought it was just a line of unused code. It was however, causing the problem. In the following line, baseLocation would be equals to null if the NETWORK_PROVIDER is disabled by the user.

long fixTime = baseLocation.getTime();

The fix: Don't try to call the method getTime() on a Null location object :) Thanks everybody!

Post a Comment for "Android Mystery Nullpointerexception Getting Last Known Location"