Android Question KVS Module and MiniSDKversion problem

Roger Daley

Well-Known Member
Licensed User
Hi All

A problem that is hard to phrase the question directly.

In the manifest this line throws an error in the KVS Module [V1.01} The same error occurs if miniSDKVersion is changed to "4". [ more on this below]
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>

The Error log in part.
keyvaluestore_initialize (java line: 256)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294 SQLITE_CANTOPEN_ENOENT[1294]): Could not open database at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:284)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java

This appears to point to the Initializee sub in the KVS module.
B4X:
'Initializes the store and sets the store file.
Public Sub Initialize (Dir As String, FileName As String)
    If sql1.IsInitialized Then sql1.Close
    sql1.Initialize(Dir, FileName, True)
    CreateTable
End Sub


The conundrum:
If I alter the Manifest to:
B4X:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="28"/>
<uses-sdk android:minSdkVersion="4" />
[Replacing the "4" with "5" brings back the KVS issue.]

I get a warning that the App was built for an older version of Android etc. If I ignore this warning, the App loads an runs OK. [No KVS issue]


Do I persue the KVS problem? Help!!!
Do I just run with the "Old Version" warning?

Any thoughts?
Regards Roger


EDIT: Code in Activity Create that calls the KVS. kvs.initialize appears twice in this code, as I am installing fresh on each occasion it will be the second instance that is causing the current issue. If I install using Version "4" the change to Version "5" and install over the top I get a third problem of views appearing in the wrong order. IE I can see views that should be hidden behind others.

B4X:
        If File.Exists(File.DirDefaultExternal, "datastore") Then
            kvs.Initialize(File.DirDefaultExternal, "datastore")
        Else
            For FNM = 0 To 15                                'Write "Strings" in to Recording
                For STEPS = 0 To 999
                    For DATA2 = 0 To 1
                        Recording(FNM,STEPS,DATA2) =  ""    'Recording2(FNM,STEPS,DATA2)
                    Next
                Next   
            Next   
            
            For FNM = 0 To 15                                'Write "Strings" in to Results
                For STEPS = 0 To 4
                    For DATA2 = 0 To 1
                        Results(FNM,STEPS,DATA2) = ""        'Results2(FNM,STEPS,DATA2)
                    Next
                Next
            Next
            
            For FCol = 0 To 15                                'Write "Strings" in to Fcolours
                Fcolours(FCol) = ""                           'Fcolours2(FCol)
            Next
            
            kvs.Initialize(File.DirDefaultExternal, "datastore")
            kvs.PutObject("history", History)
            kvs.PutObject("storelist", storelist)
            kvs.PutObject("fnumlist", FNumList)
            kvs.PutObject("Recording", Recording)
            kvs.PutObject("Results", Results)
            kvs.PutObject("Settings", Settings)
            kvs.PutObject("Fcolours", Fcolours)
        End If
 
Last edited:

Roger Daley

Well-Known Member
Licensed User
Hi All,

I think someone is going to tell me to post this as a new question but I will start here as it is in context.

In trying to solve the problem above I deleted KeyValueStore [1.01] module and included KeyValueStore2 and changed the code appropriately.

Previously Getting a string from KVS was not an issue.
EG.
Recording is a String.
B4X:
Recording  = kvs.Getobject("Recording")
Worked.

With KVS2
B4X:
Recording  = kvs.Get("Recording")
does not work, giving an error.

Logger connected to: samsung SM-A705YN
--------- beginning of main
Copying updated assets files (8)
** Activity (main) Create, isFirst = true **

Error occurred on line: 426 (Main)
java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[][][]
at b4a.C_Calc.main._activity_create(main.java:3402)
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.C_Calc.main.afterFirstLayout(main.java:105)
at b4a.C_Calc.main.access$000(main.java:17)
at b4a.C_Calc.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7094)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
** Activity (main) Resume **

Obviously KVS does not like strings.

I tried the following.

B4X:
Sub ObjectToString(obj As Object) As String
    Dim ser As B4XSerializator
    Dim su As StringUtils
    Return su.EncodeBase64(ser.ConvertObjectToBytes(obj))
End Sub


        Private ListObject As List
   
        ListObject.Initialize
        ListObject  = kvs.Get("Recording")             
        Recording = ObjectToString(ListObject)
        'Recording  = kvs.Get("Recording")


line 12 throws a "Types do not match" error, any thoughts.
 
Last edited:
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Thanks Erel

I should have done a new post on the last part. Sorry about that.

As it appears I will need to roll back to KSV1. 01 it means I am still looking for the answer to the first part of this post. An answer on that would be great.

Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Original problem solved. First it was old code that I should have updated.

Source of problem:
B4X:
kvs.Initialize(File.DirDefaultExternal, "datastore")
Using this code with
<uses-sdk android:minSdkVersion="4" />
in the manifest does not cause a problem with KVS version 1.01 and an Array of Strings can be saved.

Updating to
<uses-sdk android:minSdkVersion="5" />
causes KVS version 1.01 to crash.

Changing the code to what it should always have been solves the problem.
B4X:
kvs.Initialize(File.DirInternal, "datastore")

Regards Roger
 
Upvote 0
Top