Android Question Error with java.lang.NumberFormatException

fbritop

Active Member
Licensed User
Longtime User
I cannot guess why an error is thrown regarding a String operation.
Before I was putting together a string and an object Tag. Thought that was an error to a internal reference from the tag, but even by joining two strings, keeps throwing the error.

For example is this piece of code:
B4X:
    Dim data As String="FLAG=OBJECT&ACTION=CREATE&idShift=" & shift.Get("idShift")
    Log(data)
    If canContinue And altitude.Tag<0 Then
        CallSub2(Main, "setToast", CreateMap("msg":"Debe seleccionar la altura de remolque", "verticalPosition":20, "colorBg": col.clrWarning, "colorText":Colors.White))
        canContinue=False
    Else
        data=data & ("&altitude=" & "1450") 'altitude.Tag) '<-- THIS IS LINE 1345 FROM THE LOGS BELLOW
    End If

B4X:
FLAG=OBJECT&ACTION=CREATE&idShift=2024680
Error occurred on line: 1345 (userShiftsLogs)
java.lang.NumberFormatException: For input string: "java.lang.Object@4973580"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:63)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1082)
    at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1029)
    at cl.planeadores.clsbutton._btn2_click(clsbutton.java:318)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7509)
    at android.view.View.performClickInternal(View.java:7486)
    at android.view.View.access$3600(View.java:841)
    at android.view.View$PerformClick.run(View.java:28710)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8056)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
 

Xandoca

Active Member
Licensed User
Longtime User
Why are you putting parantheses ( and ) "data=data & ("&altitude=" & "1450")"?
have you tried removing them?
data=data & "&altitude=" & "1450"
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
Why are you putting parantheses ( and ) "data=data & ("&altitude=" & "1450")"?
have you tried removing them?
data=data & "&altitude=" & "1450"
Before that, I was using a string builder, so the parethesis where kept, but anyway removing them will not remove the error (I though it was something related to the String Builder but it was not)
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
Before that, I was using a string builder, so the parethesis where kept, but anyway removing them will not remove the error (I though it was something related to the String Builder but it was not)
You're right about parentheses.
Sorry I couldn't help you.
Just for curiosity I've created a B4A project with the code below and it works:
B4X:
    Dim shift As Map
    shift.Initialize
    shift.Put("idShift",20246800)
    Dim data As String="FLAG=OBJECT&ACTION=CREATE&idShift=" & shift.Get("idShift")
    Log(data)
    data=data & ("&altitude=" & "1450")
    Log(data)
Is the same code are you trying?
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
You're right about parentheses.
Sorry I couldn't help you.
Just for curiosity I've created a B4A project with the code below and it works:
B4X:
    Dim shift As Map
    shift.Initialize
    shift.Put("idShift",20246800)
    Dim data As String="FLAG=OBJECT&ACTION=CREATE&idShift=" & shift.Get("idShift")
    Log(data)
    data=data & ("&altitude=" & "1450")
    Log(data)
Is the same code are you trying?
Yes, the same. It was working a couple of weeks ago, so I dont know where this error came from. I´ve updated now to the beta version, but the error keeps going
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upload a small project which shows the issue
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
I can't reproduce it. Your stack trace shows an error in anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:63) where it seems to be trying to cast a Double value to the more generic Number type and failing. As this is a Debug method I cannot for the life of me imagine how this error can exist in Release compiled code. As DonManfred says, you would need to post a cut-down project that produces the error - who knows, in cutting it down you may find the real problem!
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Sometimes the error is generated a line above, even if it points to another

The problem is that altitude.Tag does not contain anything that can be parsed as a number (seems that it contains a reference to an object, and when it tries to cast it to something comparable, results in "java.lang.Object@4973580".)
Check if it works
B4X:
   altitude.Tag=-2 '<-- forcing it to be a number, will work
   'altitude.Tag = "AABB"      '<-- force it to a string, and it will give you the same exact error, but with "AABB" instead of "java.lang.Object@4973580"
   If canContinue And altitude.Tag<0 Then
....
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
I can't reproduce it. Your stack trace shows an error in anywheresoftware.b4a.debug.RDebugUtils.numberCast(RDebugUtils.java:63) where it seems to be trying to cast a Double value to the more generic Number type and failing. As this is a Debug method I cannot for the life of me imagine how this error can exist in Release compiled code. As DonManfred says, you would need to post a cut-down project that produces the error - who knows, in cutting it down you may find the real problem!
For sure the problem is not the number, is somewere else, but I cannot seem to find it where
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I get the same error message when nothing is assigned to tag. In this case though it bombs out at the comparison line, not the string concatenation line.

B4X:
    Dim data As String = "test"
    'Dim Tag As Object = "1234F" 'Works
    'Dim Tag As Object = "83.333" 'Works
    Dim Tag As Object 'Bombs
    If Tag < 0 Then 'Bombs right here
        Log("less than")
    Else
        data = data & ("&altitude=" & Tag)
        Log(GetType(Tag))
        Log(data)
    End If
Output:
java.lang.NumberFormatException: For input string: "java.lang.Object@45c8e616"
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2054)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:543)
at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:412)
at b4j.example.main._appstart(main.java:93)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
at b4j.example.main.main(main.java:29)
So maybe somewhere else some code gets skipped that sets the Tag property of your altitude variable.
 
Upvote 0

fbritop

Active Member
Licensed User
Longtime User
I get the same error message when nothing is assigned to tag. In this case though it bombs out at the comparison line, not the string concatenation line.

B4X:
    Dim data As String = "test"
    'Dim Tag As Object = "1234F" 'Works
    'Dim Tag As Object = "83.333" 'Works
    Dim Tag As Object 'Bombs
    If Tag < 0 Then 'Bombs right here
        Log("less than")
    Else
        data = data & ("&altitude=" & Tag)
        Log(GetType(Tag))
        Log(data)
    End If
Output:

So maybe somewhere else some code gets skipped that sets the Tag property of you altitude variable.
Thanks, will check it out, as there are several parts where the tag gets its value, and it it init in diferent stages. Will post results tomorrow.... thanks again
 
Upvote 0
Top