Estimote / Android-Fleet-Management-SDK

Estimote Fleet Management SDK for Android
https://developer.estimote.com
MIT License
836 stars 451 forks source link

stopRanging issues #272

Closed rajeshkanna777 closed 6 years ago

rajeshkanna777 commented 6 years ago

java.lang.RuntimeException: Unable to stop service com.wrkspot.employee.backgroundservice.BeaconService@f937e2f: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.estimote.coresdk.service.BeaconManager.stopRanging(com.estimote.coresdk.observation.region.beacon.BeaconRegion)' on a null object reference at android.app.ActivityThread.handleStopService(ActivityThread.java:3344) at android.app.ActivityThread.-wrap27(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.estimote.coresdk.service.BeaconManager.stopRanging(com.estimote.coresdk.observation.region.beacon.BeaconRegion)' on a null object reference at com.wrkspot.employee.backgroundservice.BeaconService.onDestroy(BeaconService.java:188) at android.app.ActivityThread.handleStopService(ActivityThread.java:3327) ... 8 more

Poberro commented 6 years ago

It looks like exception is coming from your code. Service is trying to call stopRanging on beaconManager that is not initialised. Check if you are initialising BeaconManager in your BeaconService or maybe you are setting it null and then calling stopRanging Easy fix is to just check if beaconManager is not null

if (beaconManager!=null) {
  beaconManager.stopRanging(region);
}