Android Question [SOLVED] strange behaviour Keyvaluestore

eurojam

Well-Known Member
Licensed User
Hi all,
I have a problem with the keyvaluestore class (kvs). The kvs will be created with B4J and contains some information which I use as content in a self-guided-tour app, mainly html with base64 encoded images. some of the produced kvs are showing normal behaviour in B4A. But some of the kvs, depending on the images in the html-code could not be loaded in B4A (in B4J they are ok and can be loaded...).

The error is in: keyvaluestore_getobjectinternal
java.lang.IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.

The testcode is pretty short:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

Type POI (id As Int, name As String, teaser As String, text As String, factsTitle As String, facts As String, Latitude As Double , Longitude As Double, _
          SliderBild1 As String, sliderBild2 As String, sliderText1 As String, sliderText2 As String, ARBild As String, ARAngle As Int, _
          Media1 As String, Mediasize1 As Double, Media2 As String, Mediasize2 As Double, icon As String, dist As Double)

Private POImap As Map

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("1")
   Dim f As String
 
   f = "testcontent_error.app" 'this produces the error
   f = "testcontent.app"  'this kvs makes no error
 
   If FirstTime Then
     File.Copy(File.DirAssets,f, File.DirInternal, f)
   End If
 
  Dim kvs As KeyValueStore 
  kvs.Initialize(File.DirInternal,f)
  POImap = kvs.getObject("poimap")
 
  Dim p As POI
  p = POImap.GetValueAt(1)
  Log(p.text)  'output html with images base64 encoded
  Dim html As String
  html = p.text
  html = html.replace("contenteditable=" & Chr(34) & "true" & Chr(34), "contenteditable=" & Chr(34) & "false" & Chr(34))    'make the html non editable
  WebView1.LoadHtml(html) 'show page of html
End Sub

The whole project can be downloaded here (https://dl.dropboxusercontent.com/u/23685552/test.zip) and contains two kvs: testcontent_error.app (produces an error in B4A) and testcontent.app (error free in B4A). The difference is only one POI object (html page with images).

Any help on that issue will be appreciated...

Best
Stefan
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
1. You should move kvs to the Starter service.

2. Calling Map.GetValueAt is a mistake in most cases. You should use For Each instead.

3. KVS is not based on B4XSerializator or RAF.WriteB4XObject. This means that the serialized data is not compatible with other platforms.

You can create a modified version of KVS that uses WriteB4XObject / ReadB4XObject. The only reason that KVS uses the other methods is that it was written before B4XSerializator was available.
 
Upvote 0

eurojam

Well-Known Member
Licensed User
3. KVS is not based on B4XSerializator or RAF.WriteB4XObject. This means that the serialized data is not compatible with other platforms.
Thank's Erel. The error occurs before the RAF action in the KVS class at:
B4X:
Dim buffer() As Byte = c.GetBlob2(0)
this is IMO a SQL problem, which I don't understand. I can save the blob as file with a sqlite tool (sqlmanager) and then open it with b4a and read the B4XObject without error.
 
Upvote 0
Top