-1

I'm getting:

 Caused by: java.lang.NullPointerException
        at android.content.ContextWrapper.getSystemService(ContextWrapper.java:423)

when the app:

    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

The code which throws the exceptions is:

421:    @Override
422:    public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
423:        mBase.grantUriPermission(toPackage, uri, modeFlags);
424:    }

(The debugger shows mBase as being null in the call.)

I have checked:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

and debugged:

context={MyService@830033501600}

Any ideas?

fadedbee
  • 42,671
  • 44
  • 178
  • 308

2 Answers2

1

It seems that you have to use Activity context to get Location Manager.

Was your context an application context? Try changing it to Activity.

Edit:

If you are in Service, run getSystemService in onCreate()

Derek Fung
  • 8,171
  • 1
  • 25
  • 28
0

Somehow you need to extend Activity class where you will use getSystemService method

Anirban Bhui
  • 6,373
  • 1
  • 11
  • 15