Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android RuntimeException with LocationProviderChangedReceiver #80

Closed
sebastien-roch opened this issue Jun 5, 2016 · 6 comments
Closed

Comments

@sebastien-roch
Copy link

Hi,
thanks for the nice plugin. Unfortunately it crashes on my device with the following error and stacktrace:

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
E/AndroidRuntime(21471):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2591)
E/AndroidRuntime(21471):    at android.app.ActivityThread.access$1700(ActivityThread.java:148)
E/AndroidRuntime(21471):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1360)
etc...

It seems that on line 837, instance is null. Don't know if it's always null or only sometimes.
I think the thing is fixable by registering the BroadcastReceiver in-line (and not through the manifest) so that we can keep a reference of the CordovaPlugin. But the question is more: why am I the only one encountering this bug?

Any idea? thanks
Android version 5.0, Cordova 6.2, plugin freshly installed.

@pazel-io
Copy link

pazel-io commented Jun 6, 2016

You are not the only one having this issue, I have the exact same problem!
I think your solution can fix it.

I also tested on Android 6 with Cordova 6 and it has the same issue!
The instance reference on line 837 can be null sometimes. I am not sure about the reason.
A null check can temporarily fix the problem, but needs to be fixed properly.

@stjerntind
Copy link

Tried that today, same problem for me.

@stjerntind
Copy link

Did some testing: The problem is that initialize() only gets called (and thus instance set) when interacting with the Java component of the plugin. registerLocationStateChangeHandler() is only interacting with the JavaScript part and then instance remains unset.

As a workaround I'm now just calling one other function to initialize the plugin and everything is so far looking well.

@nicoabie
Copy link

nicoabie commented Jun 8, 2016

I haven't tested this but a fix would be loading the plugin as soon as the application launches.
Cordova has a single instance of every plugin but gets initialized the first time the user calls it from javascript.

So to have it initialized on load time we should create a pull request (not having time today) changing

<feature name="Diagnostic" >
<param name="android-package" value="cordova.plugins.Diagnostic"/>
</feature>

to

<feature name="Diagnostic" >
<param name="android-package" value="cordova.plugins.Diagnostic"/>
<param name="onload" value="true" />
</feature>

in the plugin manifest.

@dpa99c
Copy link
Owner

dpa99c commented Jun 10, 2016

Sorry it's taken a while - just got back from holiday.

This is resolved by commits 4410762 and 92f64de and published to npm as [email protected]

@dpa99c dpa99c closed this as completed Jun 10, 2016
@dpa99c
Copy link
Owner

dpa99c commented Jun 11, 2016

Note that [email protected] supersedes this to fix #85.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants