Android Question Invalid double: "null" after updating KeyValueStore

LucaMs

Expert
Licensed User
Longtime User
I was using an "old" version of KeyValueStore. Having found this problem:
https://www.b4x.com/android/forum/posts/557508/

I replaced the old class with the latest one (and replaced all PutSimple and GetSimple with Put and Get).

Running the project, I get:
java.lang.NumberFormatException: Invalid double: "null"



executing the assignment LastVersion = Version(0) (as you can see LastVersion is a string variable so this does not make sense [also Version is an array of strings]).

KeyValueStore is not involved in any part of this phase (GetOnlineVersion is a resumable sub which downloads a simple string from Internet, splits it and returns Version(), correctly).

How could this have happened?


Thank you
 
Last edited:

sorex

Expert
Licensed User
Longtime User
you need to remove that &hl=it from the url as that will force it to have italian content.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I made the mistake of setting Italian as default language but the English translation is there. I'm afraid I can not change it; I'll see.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Back to this thread topic about the invalid double error.

The error reported is indeed confusing. It actually happens on the next line:
B4X:
If Starter.gVersionName < Version(0) Then
If you check the value of Starter.gVersionName you will see that it is "null".

The problem is in this code:
B4X:
gVersionName = KVS.Get("VersionName")
If gVersionName.Length = 0 Then
   gVersionName = Application.VersionName
   KVS.Put("VersionName", gVersionName)
End If
KVS.Get doesn't return an empty string when the key is not found. It returns Null (because the return type is Object).

The Null is converted to "null" when you assign it to a string.

A simple solution is to change the code to:
B4X:
gVersionName = KVS.GetDefault("VersionName", "")
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Thanky you, Erel.

Now I understand: object management is completely different in KVS2 compared to KVS; in fact there is no distinction GetObject - GetSimple. Interesting to read the code of both classes.



[Note that in my code I used KVS to which I added two methods, PutSimple2 and GetSimple2 to get a default value:

UID = KVS.GetSimple2(KVS_UID, " ")

but I have not used them for gVersionName ]
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…