question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NPE during attempt connection with device

See original GitHub issue
  • Device: [Motorola Moto g7 Power]

  • OS: [Android 10, API 29]

  • React Native version: [0.63.1]

  • RN Bluetooth Classic version: [1.60.0-rc.6]

Describe the bug When I try to connect with device, then an error appears: NPE in native module (android). In details error comes from method public void connectToDevice(String address, ReadableMap parameters, Promise promise) in RNBluetoothClassicModule

To Reproduce Steps to reproduce the behavior:

  1. Start discovery
  2. Try to connect with device with invoking: connect = async (address: string): Promise<BluetoothDevice> => { return await RNBluetoothClassic.connectToDevice(address); };
  3. See error as mentioned above.

Logs CatalystInstanceImpl caught native exception java.lang.NullPointerException: Attempt to invoke interface method 'java.util.HashMap com.facebook.react.bridge.ReadableMap.toHashMap()' on a null object reference at kjd.reactnative.bluetooth.Utilities.mapToProperties(Utilities.java:33) at kjd.reactnative.bluetooth.RNBluetoothClassicModule.connectToDevice(RNBluetoothClassicModule.java:728) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loop(Looper.java:241) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226) at java.lang.Thread.run(Thread.java:919)

Expected behavior An error not appear, get default parameters or the method should require additional parameters.

I’m not sure i made something mistake so please read it and tell me am i wrong or it’s just bug in code. This error appears when i try to establish connection with real device by invoking code as mentioned in 2 step. Thank you for any answer. I really appreciate your work, specially the part with iOS. Im considering to use your library but i have a little problem with android module.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kenjdavidsoncommented, Jan 19, 2021

First off, if you’re attempting to connect to an unpaired device, I don’t know what will happen. I’ve never attempted it. Looking at the code for connectToDevice it’s definitely not checking that the device is paired before attempting it.

(but you just added stack trace, so it doesn’t look like that)

The line in question Properties properties = Utilities.mapToProperties(parameters); definitely looks like the second parameter of public void connectToDevice(String address, ReadableMap parameters, Promise promise) is null.

I thought that I had defaults set in both:

BluetoothDevice.ts#connect() BluetoothModule.ts#connectToDevice()

The latter being the most important, but I guess not. You should be able to get around it by

RNBluetoothClassic.connectToDevice(address, {});

Super shady, but should be doable until I add in the defaults.

Good catch!

0reactions
kenjdavidsoncommented, Jan 20, 2021

Was able to replicate and resolve this on Android.

v1.60.0-rc.7 available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - What is a NullPointerException, and how do I fix it?
The NullPointerException (NPE) typically occurs when you declare a variable but did not create an object and assign it to the variable before...
Read more >
Cisco 7200 Series Network Processing Engine NPE-400
The 7200 NPE-400 offers a variety of options for customers looking to maximize value for specific applications in their network, including customer premise ......
Read more >
NPE while attempting to install APKS #86 - google/bundletool
Describe the bug Installing from apks to a connected device cause NPE Bundletool version(s) affected Version: 0.10.0 Stacktrace [BT:0.10.0] ...
Read more >
Bug in Network Service Discovery Example Can Lead to NPE ...
I've found that removing the call "mNsdManager.stopServiceDiscovery(this);" from onStartDiscoveryFailed() prevented the null pointer exception from being thrown ...
Read more >
[SOLVED] Problem # NPE: MPLAB X IDE v5.15
while trying to debug my code, MPLAB is throwing two NPE. ... Connecting to MPLAB PICkit 3. ... Target device PIC32MX250F128D found.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found