Android Question BleManager2 issue

NeoTechni

Well-Known Member
Licensed User
Longtime User
starter_readdata (java line: 305)
java.lang.RuntimeException: Service not found
at anywheresoftware.b4a.objects.BleManager2.getService(BleManager2.java:260)
at anywheresoftware.b4a.objects.BleManager2.readableCharsFromService(BleManager2.java:243)
at anywheresoftware.b4a.objects.BleManager2.ReadData2(BleManager2.java:194)
at anywheresoftware.b4a.objects.BleManager2.ReadData(BleManager2.java:186)
at b4a.example.starter._readdata(starter.java:305)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:831)
at b4a.example.main._polldata(main.java:1138)
at b4a.example.main._sectimer_tick(main.java:1261)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Any thoughts?
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
I tried encapsulating the code in try/catch but it is still crashing.
B4X:
Try
       manager.ReadData(KeyStart & 0 & KeyEnd)
       WaitingForData=True
     Catch
       WaitingForData=False
     End Try
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I've double checked and I'm using the right service IDs, as they work one time on the device, but sometimes not the next.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
There is, as it's a dedicated service for that device for a specific feature, and it's been detecting it fine up till a random point. But is there a way to gracefully fail though? try/catch didn't work.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Recheck your code. The services are discovered once during connection and then the same list of services is used each time.

If you want to catch this error then you can use this code:
B4X:
Dim jo As JavaObject = manager
Try 
jo.RunMethod("getService", Array(<your service>))
 Manager.ReadData(...)
Catch
 Log("Service not found.")
 End Try

Note that the service id is case sensitive.
 
Upvote 0
Top