Android Question Invalid double: "null" after updating KeyValueStore

Discussion in 'Android Questions' started by LucaMs, Jan 10, 2018.

  1. LucaMs

    LucaMs Expert Licensed 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"

    upload_2018-1-10_4-51-23.png

    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: Jan 10, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should post the full error message from the logs.
     
  3. LucaMs

    LucaMs Expert Licensed User

    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    *** Service (httputils2service) Create ***
    ** Service (httputils2service) Start **
    Error occurred on line: 269 (Main)
    java.lang.NumberFormatException: Invalid double: "null"
    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
    at java.lang.StringToReal.parseDouble(StringToReal.java:269)
    at java.lang.Double.parseDouble(Double.java:295)
    at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:50)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1717)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
    at dalvik.system.NativeStart.main(Native Method)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that this error happens on that line. Best if you can reproduce it in a small project and upload it.
     
  5. LucaMs

    LucaMs Expert Licensed User

    Debug mode, using F8, the error happens executing that line:

    LastVersion = Version(0)

    not so easy :(
     
  6. Filippo

    Filippo Expert Licensed User

    try log(version (0)), and see what the output is.
     
  7. LucaMs

    LucaMs Expert Licensed User

    upload_2018-1-10_9-38-45.png

    but I will try.
     
  8. LucaMs

    LucaMs Expert Licensed User

    Even if it is clear that the error cannot be there, because LastVersion is a String, so it can accept texts and numbers, I did it and the log is normal, 1.0.

    I tried adding a Sleep(500) before the if test, just to see if in this way the error happened elsewhere but it's the same.

    I will try to reproduce this situation in a test project (not now :(), but I think that in a new project this error will not happen; maybe attempting to do the same steps, ie initially adding the old class, run the project and then replacing the class.

    [I'm stil "working" :)() with b4a 7.30 but this error happens with v. 7.80 too]
     
  9. tigrot

    tigrot Well-Known Member Licensed User

    Remember Luca that in C and C++ null is string terminator. My favourite nightmare! I don't know if java uses a descriptor for strings or a pointer to a null terminate string...
     
    lemonisdead and LucaMs like this.
  10. LucaMs

    LucaMs Expert Licensed User

    OK but I'm not assigning a value to a variable of type double.
    There is something corrupted, I think.

    uhm... Trying using type object...
     
  11. LucaMs

    LucaMs Expert Licensed User

    Same (tried first declaring only LastVersion as object and then both - Version() too).
     
    Last edited: Jan 10, 2018
  12. Star-Dust

    Star-Dust Expert Licensed User

    Try
    Code:
    LastVersion = Version(0).Replace(".",",")
    Or

    Code:
    LastVersion = "Ver." & Version(0)
     
  13. Filippo

    Filippo Expert Licensed User

    what happens in the sub "GetOnlineVersion"?
    How is the variable version filled?
     
  14. LucaMs

    LucaMs Expert Licensed User

     
  15. Filippo

    Filippo Expert Licensed User

    are you sure?
     
  16. LucaMs

    LucaMs Expert Licensed User

    Yes :)
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Add some log messages:
    Code:
    Wait For (...) ...
    Log(Version)
    Log(GetType(Version))
    Log(Version(0))
    Log(GetType(LastVersion))
    Log("A: " & (LastVersion = Version(0)))
    What is the output?
     
  18. Star-Dust

    Star-Dust Expert Licensed User

    See if the error is not right in this ResumableSUb. It could go on with not having the necessary data yet.

    Better if you put the sub GetOnlineVersion so we can see it
     
  19. LucaMs

    LucaMs Expert Licensed User

    --------------------
    [Ljava.lang.String;@21ec12d8
    [Ljava.lang.String;
    1.0
    java.lang.String
    java.lang.String
    --------------------

    This one crashes the app:
    Log("A: " & (LastVersion = Version(0)))

    LastVersion's value is its default value (Dim LastVersion As String = "") before that log, because the crash happens when I try to set it to Version(0)
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    If you like you can send me the project and I'll test it here.
     
    LucaMs likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice