Android Question kvs = null but doesn't act as null

Startup

Active Member
Licensed User
Longtime User
I test for kvs = null (having assigned nothing to it) and mouseover shows it is null but the if-then-else test displays not null in the toast message Why is this?
Here's all the code.

B4X:
Sub Process_Globals
    Private kvs As KeyValueStore
End Sub
Sub Activity_Create(FirstTime As Boolean)
    kvs.Initialize(File.DirDefaultExternal, "datastore")
    If kvs = Null Then
        ToastMessageShow("null",True)
    Else
        ToastMessageShow("not null",True)
    End If
End Sub
 

eurojam

Well-Known Member
Licensed User
Longtime User
a kvs can not be NULL, it is a sqlite DB with one Table which can have records or not. you can check for example something like this
B4X:
 Dim l As List = kvs.ListKeys
If l.Size = 0 Then
    'empty
Else
     'not empty    
End If
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
KVS won't be null once you have Dimmed it at it creates the (uninitialized) variables that are in Class_Globals in the constructor. What are you trying to test for?

If you want to see if it's empty you can do:
B4X:
Log(kvs.ListKeys.Size = 0)
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
a kvs can not be NULL, it is a sqlite DB with one Table which can have records or not. you can check for example something like this
B4X:
 Dim l As List = kvs.ListKeys
If l.Size = 0 Then
    'empty
Else
     'not empty   
End If

Oh that explains it. Thanks!
 
Upvote 0

Startup

Active Member
Licensed User
Longtime User
KVS won't be null once you have Dimmed it at it creates the (uninitialized) variables that are in Class_Globals in the constructor. What are you trying to test for?

If you want to see if it's empty you can do:
B4X:
Log(kvs.ListKeys.Size = 0)
KVS won't be null once you have Dimmed it at it creates the (uninitialized) variables that are in Class_Globals in the constructor. What are you trying to test for?

If you want to see if it's empty you can do:
B4X:
Log(kvs.ListKeys.Size = 0)

OK. Gotit now. Thanks!
 
Upvote 0
Top