Android Tutorial KeyValueStore class - Simple and efficient key/value data store

Status
Not open for further replies.

freetoair

Member
Licensed User
Longtime User
I can not understand why the list "TempList" is not initialized after calls: "Dim TempList As List = kvs.GetObject(lblCustom.Text)"
B4X:
Sub Activity_Resume
      kvs.PutObject("Start",lblCustom.Text)
     Dim TempList As List =kvs.GetObject(lblCustom.Text)
     SeekBar1.Value = TempList.Get(0)
    SeekBar2.Value = TempList.Get(1)
     SeekBar3.Value = TempList.Get(2)
     Convert.konverzija(0)
    VUdata = False
End Sub
 

freetoair

Member
Licensed User
Longtime User
Yes, I found it, during the declaration "Start" I added one more space. Thanks DonManfred !
 

tufanv

Expert
Licensed User
Longtime User
Hello
When i try to check if there is a key "gecerlitarih"
B4X:
If kvs.GetEncryptedObject("gecerlitarih","pass") = "ok" Then
I am getting
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
it points to "return null" line of Private Sub getObjectInternal(Key As String, decrypt As Boolean, password As String) As Object

Am i doing stg wrong ?
 

tufanv

Expert
Licensed User
Longtime User
I just put a try before the code and catch - end try at the end. Now it works correctly. Maybe it was because that there werent any key "gecerlitarih"
Please start a new thread for this question and post the relevant code.
 

postasat

Active Member
Licensed User
Longtime User
Hi,

I'm searching for a software to edit on windows the file created with B4A and kvs.
I tried DBBrowser for SQLite, I can open the file but I can't' see my data.

Thanks.
 

derez

Expert
Licensed User
Longtime User
I'm searching for a software to edit on windows the file created with B4A and kvs.
I tried DBBrowser for SQLite, I can open the file but I can't' see my data.
SQlite_Expert does it !
 

Cebuvi

Active Member
Licensed User
Longtime User
Hello,

I have also found that the message:

"An error has occured in sub:Keyvaluestore_initialize (java line:251)
android.database.sqlite.SQLiteCantOpenDatabaseException:
unknown error (code 14): Could not open database
Continue?"

occurs when the manifest it has:
B4X:
android:targetSdkVersion="23"/>

Setting the manifest for APi 22, no longer the problem occurs.

What would be the solution to use KeyValueStore class with API 23?

Thanks.
 

Cebuvi

Active Member
Licensed User
Longtime User
Thanks Manfred,

I've tried adding in the main activity


B4X:
Permission.Initialize
   
    Log ("Done - Has permission = " & Permission.CheckPermission ("android.permission.WRITE_EXTERNAL_STORAGE"))
   
    If Permission.CheckPermission ("android.permission.WRITE_EXTERNAL_STORAGE") = False Then   
        Permission.RequestPermission ("android.permission.WRITE_EXTERNAL_STORAGE")       
    End If

and gives the error before requesting permission.

Cesar
 

Carlos Serra

New Member
Licensed User
Longtime User
Dear Erel,

i've change it and still have that error:

Copying updated assets files (8)
** Service (starter) Create **
Error occurred on line: 13 (KeyValueStore)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:37)
at b4a.example.keyvaluestore._initialize(keyvaluestore.java:54)
at b4a.example.starter._service_create(starter.java:140)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at b4a.example.starter.onCreate(starter.java:53)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2529)
at android.app.ActivityThread.access$1600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
** Service (starter) Start **

Project Data:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.


Any other idea?

thanks
 

Douglas Farias

Expert
Licensed User
Longtime User

try change
B4X:
File.DirDefaultExternal

to

B4X:
File.DirInternal
 

Carlos Serra

New Member
Licensed User
Longtime User
Hi Douglas,

you are right. in true was an issue with Android Emulator (i've forget to put available space on Memory Card).

Thanks
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel.
Is it possible to store more than one (persistent) "dataset" within a single KVS store assuming to use a (key) naming convention to handle each (persistent) "dataset".
So each (persistent) dataset within the KVS store ideally can represent a SQL db data.

For example each key could have a prefix that represent the (persistent) dataset name and after the key prefix I can have a unique key in order to identify the item within a specific dataset.

Could be a good approach to handle different data entity within the same KVS store?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…