Android Question java.lang.NumberFormatException

Sofiya

Member
Licensed User
Hello everyone,
I am trying to parse int32 value from API to double in B4A but unfortunately it shows error java.lang.NumberFormatException. For API, i use C#.net. I insert my code:
B4X:
Sub BtnKot_Click
    Dim job_5, job_6 As HttpJob
    job_5.Initialize("job", Me)
    job_6.Initialize("", Me)
'    job_5.PostString("http://192.168.1.4/posapi/insertKot/addkot",JSON)
    job_6.Download("http://192.168.1.4/posapi/kot/selectdata")
    
    k = 0
    k = m.get("KotNo")
        
    For i = 0 To Grid.RowCount - 1
        job_5.Download2("http://192.168.1.4/posapi/insertKot/addkot", _
        Array As String("kotno",k,"itemcode","S","itemcategory","food","unqno",2,"reason","vcsdawre","rate",Grid.GetValue(i,2),"amount",Grid.GetValue(i,3),"quantity",Grid.GetValue(i,1),"taxrate",3,"preferencepckey",123,"kotdate",DateTime.Now,"status","A","itempckey",1234))
        k = k + 1
    Next
    
    Wait For (job_5) JobDone(job_5 As HttpJob)
    If job_5.Success Then
        Log(job_5.GetString)
        ' = job_5.GetString
    Else
        ' = job_5.ErrorMessage
        ToastMessageShow(job_5.ErrorMessage,True)
        Return
    End If
    job_5.Release
    job_6.Release
End Sub

and the error shows:
B4X:
Error occurred on line: 187 (Billing)
java.lang.NumberFormatException
    at org.apache.harmony.luni.util.FloatingPointParser.parseDblImpl(Native Method)
    at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:283)
    at java.lang.Double.parseDouble(Double.java:318)
    at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:55)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    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:507)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:2485)
    at android.view.View$PerformClick.run(View.java:9080)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3647)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)

Please help me to find the problem. Thanks in Advance.
 

MarkusR

Well-Known Member
Licensed User
Longtime User
which is "line: 187 (Billing)"

i think you try convert a string value to double,true?
it was int32 in c# but you download it as json string.
 
Last edited:
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
me thought, just log the value or make a breakpoint there and see what is in.
its not part of the click sub, so u are using a global variable.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
see above message.
say what is in m.get("KotNo")
the api is secondary.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
yes, but what is the value of it??? use log(m.get("KotNo")) or look at it at a breakpoint.
so you/we can test the conversion elsewhere easier.
you access a map by key there. exist the key and have it a value?
debug tutorial from erel:
 
Last edited:
Upvote 0

Sofiya

Member
Licensed User
I was put breakpoint at the line k = m.get("KotNo") and check the value in the watch box the value shows like this "k = m.get("KotNo") : ErrorEvaluatingExpression"
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Use log and log the hole Object m
Post the log output of
B4X:
log(m)
 
Upvote 0

Sofiya

Member
Licensed User
The log output is:
B4X:
(MyMap) {taxrate=0, baseqty=0, Itemcode=SPr, poscode=2, status=null, ItemName=Schezwan Prawns, itemcat=null, Rate=360.0, ItemPckey=7201}
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
at debug breakpoint you can also look into this map before you will run into error.
Snap_2018.05.10_13h08m22s_001_.png
but i guess u expected the key there but it was not in this map.
i think you used this m variavle elsewhere too and overwritten it.
if you use global variables use a better name.
 
Upvote 0
Top