Android Question reading value from EditText box - Invalid Double

Arf

Well-Known Member
Licensed User
Longtime 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'.
B4X:
Dim height as int
height = heightText.Text

What is the correct way do this, use a stringToInt function?
 

Arf

Well-Known Member
Licensed User
Longtime 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.
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime 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)
 
Upvote 0

Arf

Well-Known Member
Licensed User
Longtime User
and a correction, I'm actually trying to convert to float, not int:
B4X:
Dim height as Float
height = heightText.Text
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
An Empty String cannot be parsed to a Double, Int, Long, Float
 
  • Like
Reactions: Arf
Upvote 0
Top