Retrieving the location provider "gps" causes a NullPointerException in LocationManager.createProvider

by NTR » Mon, 07 Apr 2008 00:35:49 GMT


Sponsored Links
 When I try using the "gps" provider, I get the following:

ERROR/AndroidRuntime(3253): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(3253):     at
android.location.LocationManager.createProvider(LocationManager.java:
61)
ERROR/AndroidRuntime(3253):     at
android.location.LocationManager.getProvider(LocationManager.java:119)
ERROR/AndroidRuntime(3253):     at
net.lbns.mobileclient.util.LocationUtil.getLocationProvider(LocationUtil.java:
21)

Code:

public static LocationProvider getLocationProvider(Application app) {
    try {
      LocationManager locationManager = getLocationManager(app);
      return locationManager.getProvider("gps");
    }
    catch (SecurityException e) {
      return null;
    }
  }

  public static LocationManager getLocationManager(Application app) {
    return (LocationManager)
app.getSystemService(Context.LOCATION_SERVICE);
  }

The application is retrieved by using getApplication() of a sub-
activity. Any help?
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. How to manage service lifecycle when device kills it due to low memory

Hi!

I have a service that polls for data. To indicate this to the user I
have a persistent notification in the statusbar. In some cases when
the device goes low on memory it destroys the service but OnDestroy is
not called. Later when there is available memory OnCreate is called.
Is this normal behavior? I had hoped that OnDestroy would be called to
I could remove the notification in the statusbar. Now the user thinks
that the service is still running, while it has been stopped by the
OS.

In order to restart the polling how do I know that the OnCreate is
really a restart event and not first time creation of the service? I
thought about checking for the presence of the notification in the
statusbar, but I couldn't find a API to check if a notification was
showing or not.

I have not tried "SetForeground" on the service, since the service
isn't that important to the user, but maybe that would minimize the
problem...

-Christer
--~--~---------~--~----~------------~-------~--~----~

2. unexpected error in sms application

i have trying sms example.in first few times it was running verry well
in eclips.then i tried some modification so its showing error
unexpectedally closed.then i removed that application n imprted pre
one which was running but now that is also not running n showing the
same error.what should i suppose to do?
--~--~---------~--~----~------------~-------~--~----~

3. google maps question

4. Force the height of a view

5. Java N00b Test Question

6. Protecting /system/app packages from extraction

7. Jdbc driver problem