Android Question KVS returns null [Solved]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

A puzzle with KVS. I have an App with a number of Lists that I store as KVS. One list is not working.
The code below is what I inserted to try to track the problem. All Lists are handled much the same way in set up and back up, the others work this one doesn't. The full code is too large to post in it's entirety.
storelist is defined as List in the same line as the other Lists.

B4X:
        storelist.Set(7, 55)
        Log("Number Pre KVS = "&storelist.Get(7))  ' Correctly shows 55
        kvs.PutObject("storelist", storelist)
        storelist = kvs.GetObject("storelist")
        Log("Number Post KVS = "&storelist.Get(7))  'Returns null

Any suggestions gratefully received.

Regards Roger
 

jimmyF

Active Member
Licensed User
Longtime User
Just curious Roger. Which version of kvs?
I use kvs2 and have no problems with it.
Actually version 2.2 in the bas file.

No idea, though, if that is your issue or will solve the problem.

hth
-j
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Try using the Key as an numeric value.
B4X:
dim idx as Int = 7
storelist.Set(idx, 55)
        Log("Number Pre KVS = "&storelist.Get(idx))  ' Correctly shows 55
        kvs.PutObject("storelist", storelist)
        storelist = kvs.GetObject("storelist")
        Log("Number Post KVS = "&storelist.Get(idx))  'Returns null
Or as String...
B4X:
dim idx as String = "7"
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

Apology and correction of question.

The code in the original post was an over simplification of the problem.
Further investigation shows the problem is that KVS is not storing BigDecimals, but storing a null.
The following code is a more accurate representation of the problem.

B4X:
Private d1 As BigDecimal
d1.Initialize(55)       

        storelist.Set(7, d1)
        Log("Number Pre KVS = "&storelist.Get(7))  ' Correctly shows 55
        kvs.PutObject("storelist", storelist)
        storelist = kvs.GetObject("storelist")
        Log("Number Post KVS = "&storelist.Get(7))  'Returns null

The question now becomes how to save BigDecimals in KVS

Regards Roger
 
Upvote 0
Top