Android Question Error "Unfortunately Bluetooth POS Printing has stopped" when trying to enable bluetooth printer

Ganiadi

Active Member
Licensed User
Longtime User
Hi,

I Got below error log when printing on bluetooth printer when activate below procedure, anybody may help ?

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Activity.LoadLayout("main")
BtAdmin.Initialize("BlueTooth")
BTConnection.Initialize("Printer")
Dim PairedDevices As Map
PairedDevices = BTConnection.GetPairedDevices

BTConnection.ConnectInsecure(BtAdmin,PairedDevices.Get(PairedDevices.GetKeyAt(0)), 1)
End If
End Sub

Logger connected to: ADVAN ADVAN T5C
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 352)
java.util.NoSuchElementException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:353)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:379)
at java.util.LinkedHashMap$EntryIterator.next(LinkedHashMap.java:377)
at anywheresoftware.b4a.objects.collections.Map$MyMap.getEntry(Map.java:213)
at anywheresoftware.b4a.objects.collections.Map$MyMap.getKey(Map.java:193)
at anywheresoftware.b4a.objects.collections.Map.GetKeyAt(Map.java:91)
at b4a.example.main._activity_create(main.java:352)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5370)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
These are basic functions of a map, so why avoid them?
Maps are key / value collections. They are designed to be accessed based on the keys. Maps are not lists.
GetKeyAt / GetValueAt were added before the For Each loop was available, as a way to iterate over the elements.
Using them to access random elements will yield bad performance (only matters if the Map is large).

You should use For Each to iterate over the keys or values.
 
Upvote 0
Top