Android Question KVS-problem

Discussion in 'Android Questions' started by Herbert32, May 16, 2019.

  1. Herbert32

    Herbert32 Member Licensed User

    Hi,

    during changing my code to store data asynchronous in KVS it seems that I destroyed the content of a Map with 1808 entries.

    To see what happened exactly, i would like to take a look inside the stored data but seems to be not so easy...

    In the KeyValueStore-Class 'getObjectInternal' the data is read into the Object 'res' - I'm able to view the first 100 entries with the debugger but I need to see the last 20 to know more what happened.

    It's possible to pass the object 'res' to my Map but as soon as I access the Map, my app crashes also in debug-mode.

    It's important for my further development to get the intact data back but right now, i have no idea how to reach this...

    Maybe someone can push me into the right direction.

    thank you in advance

    Herbert
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Where is the error message?
     
  3. Herbert32

    Herbert32 Member Licensed User

    sorry, here:

    Code:
    Error occurred on line: 565 (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:
    1521)
        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)
     
  4. Herbert32

    Herbert32 Member Licensed User

    also the possibility to remove the broken or defect entries starting from the last in descending order will be ok - this gives me the chance to receive my important data back and check by debugging while saving new data in the new coded way what i'm doing wrong.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It doesn't happen during deserialization.

    Can you post the relevant code?
     
  6. Herbert32

    Herbert32 Member Licensed User

    Code:
    If KVS.ContainsKey("CardTrans"Then
        mCardTrans = KVS.GetObject(
    "CardTrans")
    Else
        mCardTrans.Clear
        KVS.PutObject(
    "CardTrans",mCardTrans)
    End If
    NextTransID = mCardTrans.Size+
    1
    it crashes in the line
    Code:
    NextTransID = mCardTrans.Size+1
    it also crashes when i set a breakpoint to that line and try to move the cursor over 'mCardTrans' in this line
    Code:
    mCardTrans = KVS.GetObject("CardTrans")
    to let the debugger show me mCardTrans's content in the contextmenue
     
  7. Herbert32

    Herbert32 Member Licensed User

    maybe there are Null-values written into KVS - I'm unsure as I'm not able to see whats written in
     
  8. Herbert32

    Herbert32 Member Licensed User

    Code:
    If KVS.ContainsKey("CardTrans"Then
    is true
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Try this:
    Code:
    Dim jo As JavaObject = KVS.GetObject("CardTrans")
    log(jo)
    Dim m As Map = jo.RunMethod("getObject"Null)
     
  10. Herbert32

    Herbert32 Member Licensed User

    hmmm...

    this is strange...

    by this way, I can fill my Map

    Code:
    mCardTrans = m
    after that all works as expected...
     
  11. Herbert32

    Herbert32 Member Licensed User

    if I look insite the map, I can't see wrong content - everything looks OK for me
     
  12. Herbert32

    Herbert32 Member Licensed User

    hmmm - how to find out now why

    Code:
    Dim jo As JavaObject = KVS.GetObject("CardTrans")
    log(jo)
    Dim m As Map = jo.RunMethod("getObject"Null)
    mCardTrans = m
    works while
    Code:
    mCardTrans = KVS.GetObject("CardTrans")
    doesn't work ???
     
  13. Herbert32

    Herbert32 Member Licensed User

    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:
    Code:
    Private Sub getObjectInternal(Key As String, decrypt As Boolean, password As StringAs 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:

    Code:
    *** 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:
    Code:
    Private Sub getObjectInternal(Key As String, decrypt As Boolean, password As StringAs 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:

    Code:
    *** 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:
    Code:
    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':
    Code:
    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...
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    This doesn't matter.

    Somehow you got a wrapped Map into the KVS. I'm not sure how it happened. The code I posted unwraps it.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice