Android Question Strings in KVS2 from library[Completed]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

This is a repost of a small part of a previous question. The previous question covers several issues and results in being complex, therefore no answer.
This question is limited and hopefully answerable.

In my project in trying to solve one problem changed from KeyStoreValue [1.01] module to KeyStoreValue [2.21] which is now an included library in B4A.
KSV2 is supposed to be able to support strings but it is throwing an error. Below is a test example and the error it throws.


Thanks in advance
Roger

B4X:
#Region  Project Attributes
    #ApplicationLabel: KVS Example
    #VersionCode: 1
    #VersionName: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #BridgeLogger: True
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Public kvs As KeyValueStore
    Private Stringexample(10,3) As String
    Private listExample As List
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Button1 As Button
    Private Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("Main")  
    If FirstTime Then
        listExample.Initialize      
        listExample.InsertAt(0,0)
        If File.Exists(File.DirInternal, "datastore") Then
            kvs.Initialize(File.DirInternal, "datastore")
        Else
            For AA = 0 To 9                                'Write "Strings" in to Stringexample
                For BB = 0 To 2
                    Stringexample(AA,BB) =  " "  
                Next
            Next  
            kvs.Initialize(File.DirInternal, "datastore")
            kvs.Put("Stringexample", Stringexample)  
            kvs.Put("listExample", listExample)
        End If      
        Stringexample = kvs.Get("Stringexample")                    'Error occurred on line: 50 (Main)
        listExample = kvs.Get("listExample")
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    kvs.Put("Stringexample", Stringexample)
    kvs.Put("listExample", listExample)
End Sub

Sub Button1_Click
    listExample.Add(Rnd(10,20))
    Label1.Text = Rnd(0,100)
End Sub


The error log:

Logger connected to: samsung SM-A705YN
--------- beginning of main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 50 (Main)
java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[][]
at b4a.example.main._activity_create(main.java:446)
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 b4a.example.main.afterFirstLayout(main.java:105)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7814)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
** Activity (main) Resume **
 
Top