don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
950 stars 607 forks source link

Android: java.lang.NullPointerException #773

Closed barakataboujreich closed 1 year ago

barakataboujreich commented 4 years ago

Hello, yesterday i got 7 crashes reports from firebase crashlitics. now i'm running the plugin version 1.1.9, it's been a while since we updated plugins and published the app. but this is the first time we got this crash report.

Fatal Exception: java.lang.RuntimeException Failure delivering result ResultInfo{who=@android:requestPermissions:, request=165, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS launchParam=MultiScreenLaunchParams { mDisplayId=0 mBaseDisplayId=0 mFlags=0 } (has extras) }} to activity {com.phonegap.kindoo/com.phonegap.kindoo.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.sendPluginResult(org.apache.cordova.PluginResult)' on a null object reference

android.app.ActivityThread.deliverResults (ActivityThread.java:4556) android.app.ActivityThread.handleSendResult (ActivityThread.java:4599) android.app.ActivityThread.-wrap22 (ActivityThread.java) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1715) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6816) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1563) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1451)

Caused by java.lang.NullPointerException Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.sendPluginResult(org.apache.cordova.PluginResult)' on a null object reference com.megster.cordova.ble.central.BLECentralPlugin.onRequestPermissionResult

com.megster.cordova.ble.central.BLECentralPlugin.onRequestPermissionResult (BLECentralPlugin.java:603) org.apache.cordova.CordovaInterfaceImpl.onRequestPermissionResult (CordovaInterfaceImpl.java:221) org.apache.cordova.CordovaActivity.onRequestPermissionsResult (CordovaActivity.java:509) android.app.Activity.dispatchRequestPermissionsResult (Activity.java:7507) android.app.Activity.dispatchActivityResult (Activity.java:7333) android.app.ActivityThread.deliverResults (ActivityThread.java:4552) android.app.ActivityThread.handleSendResult (ActivityThread.java:4599) android.app.ActivityThread.-wrap22 (ActivityThread.java) android.app.ActivityThread$H.handleMessage (ActivityThread.java:1715) android.os.Handler.dispatchMessage (Handler.java:102) android.os.Looper.loop (Looper.java:154) android.app.ActivityThread.main (ActivityThread.java:6816) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1563) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1451)

now BLECentralPlugin.java:603 has this line

this.permissionCallback.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, PERMISSION_DENIED_ERROR));

inside of method

public void onRequestPermissionResult(int requestCode, String[] permissions,
                                          int[] grantResults) /* throws JSONException */ {

now clearly the user is denying permission for Coarse Location Access

i tried to replicate the scenario knowing where the user is denying the permission, but non of our test phones could replicate the scenario above, even when debugging the app using android studio there is no null object returned. i can't figure out the problem, and the user sent already 3 emails about the crash.

that's the user data available:

Device Brand: samsung Model: Galaxy J3(2016) Orientation: Portrait RAM free: 296 MB Disk free: 640.33 MB

Operating System Version: 7.1.1 Orientation: Portrait Rooted: No

Crash Date: Jun 9, 2020, 10:15:00 AM App version: 3.6.4 (300064)

peitschie commented 2 years ago

Duplicate of #698