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

#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:
    If FirstTime Then
        If File.Exists(File.DirInternal, "datastore") Then
            kvs.Initialize(File.DirInternal, "datastore")
            For AA = 0 To 9                                'Write "Strings" in to Stringexample
                For BB = 0 To 2
                    Stringexample(AA,BB) =  " "  
            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
    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(
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(
at b4a.example.main.afterFirstLayout(
at b4a.example.main.access$000(
at b4a.example.main$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)
** Activity (main) Resume **