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

Attempt to invoke virtual method 'boolean java.util.LinkedList.add(java.lang.Object)' on a null object reference #732

Open
markokitanoski1 opened this issue Aug 10, 2022 · 6 comments

Comments

@markokitanoski1
Copy link

Hello there,

I am trying to implement Bluetooth connection to external Bluetooth device, but I am experiencing several issues that I can not solve:

  • documentation prefers avoiding the .reconnect() method with using combination of .close & .connect methods instead, but after successfully connecting to a device along with .connect method, device just disconnects everytime in a matter of several (approx. 6s) seconds, and causing a connect - disconnect loop.
  • I have implemented a callback which executes whenever device is disconnected to call .reconnect method but I suspect or I discovered that the .read method which I am trying to call when the device is successfully connected throws an error: Attempt to invoke virtual method 'boolean java.util.LinkedList.add(java.lang.Object)' on a null object reference when is beeing called after the .reconnect method. If I do not use reconnect method and use above implementation it causes the connect - disconnect loop but meanwhile .read function executes successfully.

I do not found any workaround.

@justin-augustine-atlascopco

I am also having this issue of
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.LinkedList.add(java.lang.Object)' on a null object reference at com.randdusing.bluetoothle.BluetoothLePlugin.queueAdd(BluetoothLePlugin.java:3197)
I only found this error when upgrading from ionic 5 to ionic 6. I would appreciate any help on this matter.

@markokitanoski1
Copy link
Author

Can this be urgently fixed by the dev team because my functionality which is using this plugin is the core of my application.

Thanks in advance!

@davidofwatkins
Copy link

Any updates on progress or workarounds for this?

I recently upgraded from v4.4.3 to v6.7.0 and started receiving this error after a BLE device disconnects unexpectedly and then reconnects. I was able to do a git bisect on this plugin within my app and determined that #694 introduced the broken change.

I'll continue to investigate the issue, but maybe @ttongsul has some ideas?

@ttongsul
Copy link
Contributor

Hello @davidofwatkins and others that may have been affected by this issue. I'm deeply sorry for the problems that my commit may have caused.

It seems that the cause is in this line here, where connection.get(keyQueue) may return null instead of a linked list. A possible solution is adding the code if (queue == null) { queue = new LinkedList<Operation>(); connection.put(keyQueue, queue); } next to the line.

Unfortunately, I don't have a working Android dev environment set up and my hands are full at the moment. It would be greatly appreciated if someone could test the solution and open up a PR.

@qpwr
Copy link

qpwr commented Jan 9, 2023

I can confirm @ttongsul s patch is working fine for me.

@DonOzOn
Copy link

DonOzOn commented Feb 3, 2023

i added below code to reconnectAction method in Native code and it worked.
LinkedList queue = new LinkedList();
connection.put(keyQueue, queue);

image

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

6 participants