Android Question reading value from EditText box - Invalid Double

Discussion in 'Android Questions' started by Arf, Jun 2, 2015.

  1. Arf

    Arf Active Member Licensed User

    I've got a EditText box set up for numbers only, into which a height number is typed.
    When I try read the content, I imagine it will be casted automatically.
    However, I get a crash on the second line below, 'Invalid Double'.
    Code:
    Dim height as int
    height = heightText.Text
    What is the correct way do this, use a stringToInt function?
     
  2. Arf

    Arf Active Member Licensed User

    Oops, ignore this question. heightText had not had a value typed in, and the initial string from the designer contained a non-numeric string.
     
  3. Arf

    Arf Active Member Licensed User

    Retract, retract! The inital string did no seem to be the problem after all.

    Still have problems. Log is below:

    java.lang.NumberFormatException: Invalid double: ""
    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
    at java.lang.StringToReal.parseDouble(StringToReal.java:248)
    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:511)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:77)
    at android.view.View.performClick(View.java:4452)
    at android.widget.Button.performClick(Button.java:148)
    at android.view.View$PerformClick.run(View.java:18428)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5365)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
    at dalvik.system.NativeStart.main(Native Method)
     
  4. Arf

    Arf Active Member Licensed User

    and a correction, I'm actually trying to convert to float, not int:
    Code:
    Dim height as Float
    height = heightText.Text
     
  5. DonManfred

    DonManfred Expert Licensed User

    An Empty String cannot be parsed to a Double, Int, Long, Float
     
    Arf likes this.
  6. klaus

    klaus Expert Licensed User

    You should put a correct default value in your EditText view.
     
    Arf 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