Search code examples
androidioscordovaphonegap-pluginscordova-plugins

OnLocationStateChange cordova application crashes


The application i am working is basically fetches users location using cordova geolocation plugin, and then show the location on the google maps.

The problem i'm facing is that when i kill the app and turn off/on the location services from settings the application crashes.

java.lang.RuntimeException: Unable to start receiver cordova.plugins.Diagnostic$LocationProviderChangedReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'void cordova.plugins.Diagnostic.notifyLocationStateChange()' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void cordova.plugins.Diagnostic.notifyLocationStateChange()' on a null object reference

enter image description here this is the screen shot of error that i got after running the app directly from Android studio

I'm using diagnostic plugin as well because i'm testing app on API 23 i-e Marshmallow, that needs run time permissions. if i remove diagnostic plugin the app crashes as soon as it starts on Marshmallow.

The app runs on API's below 23 and also it does not crashes when i turn location services On/Off.

Advices/Suggestions are welcomed.


Solution

  • This is noted as issue #85 in the plugin repo and is resolved by patch release [email protected]:

    $ cordova plugin rm cordova.plugins.diagnostic && 
      cordova plugin add cordova.plugins.diagnostic@latest