Question

I have an application in which I am getting current location at the first page. In India Application is working fine and getting current location. When we run the application in US, application is getting crashed at the first page itself and throwing IllegalArgumentException. I am including the exception details here.

Was it helpful?

Solution

The phone doesn't have any provider enabled to detect the location, i.e it is neither connected to GPS nor WI-FI, in which case the provider is being passed as null. This is assuming that you are providing provider argument to requestLocationUpdates() function by, finding the best provider, which will return null, if it can't find any.

I would first check if any provider is enabled, before proceeding any further in to this matter. To avoid passing null as a provider, check if the provider is null before calling for location update.

if (provider != null) {
      requestLocationUpdates()
} else {
      // alert user asking him to enable one of the providers.
}

This is how you do it.

HTH.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top