I went back now to a backup which I created before my last changes to be sure that I did not changed something accidently and find the same situation - cant read on the original way
But by doing this I found another strange behaviour also:
this is my original code in the KeyValueStore-Class for getObjectInternal:
Private Sub getObjectInternal(Key As String, decrypt As Boolean, password As String) As Object
Dim c As Cursor = getCursor(Key)
If c.RowCount = 0 Then
c.Close
Return Null
End If
c.Position = 0
Dim buffer() As Byte = c.GetBlob2(0)
Dim raf As RandomAccessFile
raf.Initialize3(buffer, False)
Dim res As Object
If decrypt Then
res = raf.ReadEncryptedObject(password, raf.CurrentPosition)
Else
res = raf.ReadObject(raf.CurrentPosition)
End If
raf.Close
c.Close
Return res
End Sub
'Return res' is located in Line 179 and I receive following Log while Debug-Mode:
*** Service (starter) Create ***
Error occurred on line: 179 (KeyValueStore)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at order.star.pro.starter._kvsread(starter.java:1256)
at order.star.pro.starter._service_create(starter.java:1472)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at order.star.pro.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2895)
at android.app.ActivityThread.access$1900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
** Service (starter) Start **
If I add a Line for Logging before the 'Return res', 'Return res' moves to Line 180:
Private Sub getObjectInternal(Key As String, decrypt As Boolean, password As String) As Object
Dim c As Cursor = getCursor(Key)
If c.RowCount = 0 Then
c.Close
Return Null
End If
c.Position = 0
Dim buffer() As Byte = c.GetBlob2(0)
Dim raf As RandomAccessFile
raf.Initialize3(buffer, False)
Dim res As Object
If decrypt Then
res = raf.ReadEncryptedObject(password, raf.CurrentPosition)
Else
res = raf.ReadObject(raf.CurrentPosition)
End If
raf.Close
c.Close
Log(Key)
Return res
End Sub
But look what now happens in my Log:
*** Service (starter) Create ***
ToBeUpdated
DeviceAdminLock
NoLockCredit
MC_Created
NoLockSession
NoLockTime
CheckSum1Ignore
DataWAGRU
mArtikel
DataETC
Cards
Error occurred on line: 180 (Starter)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at order.star.pro.starter._kvsread(starter.java:1256)
at order.star.pro.starter._service_create(starter.java:1472)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at order.star.pro.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2895)
at android.app.ActivityThread.access$1900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
** Service (starter) Start **
The Error occures now in Line 180 as expected - But the Log does not show 'KeyValueStore' as Module where it occours - it shows 'Starter' - one of both is false - Line-# or Module ...
but MOST curious is what happens if I set a Breakpoint in my Sub in the starter-service where I read all my Values which I stored in KVS exactly AFTER passing the content to my first 'problem-Map'...
the curiosity is that 'NO Error happens' - it only happens when the Map is touched the first time by getting it's size...
code-snippet:
If KVS.ContainsKey("Cards") Then
mCards = KVS.GetObject("Cards")
Else
mCards.Clear
KVS.PutObject("Cards",mCards)
End If
NextCardID = mCards.Size+1
If KVS.ContainsKey("EProt") Then
EProt = KVS.GetObject("EProt")
Else
EProt.Clear
KVS.PutObject("EProt",EProt)
ToBeUpdated = True
End If
Log if setting a breakpoint to Line 572 'If KVS.ContainsKey("EProt") Then':
Copying updated assets files (32)
*** Service (starter) Create ***
ToBeUpdated
DeviceAdminLock
NoLockCredit
MC_Created
NoLockSession
NoLockTime
CheckSum1Ignore
DataWAGRU
mArtikel
DataETC
Cards
Error occurred on line: 570 (Starter)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at anywheresoftware.b4a.objects.collections.Map.getSize(Map.java:111)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at order.star.pro.starter._kvsread(starter.java:916)
at order.star.pro.starter._service_create(starter.java:1472)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at order.star.pro.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2895)
at android.app.ActivityThread.access$1900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5551)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Hopefully I was able to describe all the curiosities which are happen here...
I noticed in the past that sometimes line# and module-name doesn't match in the debugging-log - but never had been able to reproduce so clear than here
But all doesn't really help - i can't find why my original code doesnt work anymore...