B4J Question java.lang.NumberFormatException: For input string:

Rob White

Member
Licensed User
Hi All,

I am getting the above error from code which has been running for 3 years!

Here is the routine in question I added it to DBUtils:-
B4X:
' Returns the next available value for the ID column of a table - RJGW
Public Sub NxtID(sql As SQL,thisTable As String,FldName As String) As Int
    Try
        Dim qStr As String = $"SELECT MAX(${FldName}) FROM ${thisTable};"$
        Dim MaxL As List = ExecuteMemoryTable(sql,qStr,Null,0)      
        Dim MaxNo As Int = -1
        If MaxL.Size >= 0 Then
            ' Was MaxNo = MaxL.Get(0) + 1
            ' Teased apart to find problem
            Dim mxStr As String = MaxL.Get(0)
            Log(MaxL.Get(0))
            Log(mxStr)
            MaxNo = mxStr
            MaxNo = MaxNo + 1
        Else
            MaxNo = 0
        End If
    Catch
        Act.LogDate($"$DbUtils.NxtID ${LastException}"$)
        Return 0
    End Try
    Return MaxNo
End Sub

The log messages are :-

Evt fired --->butnew_clicked Number params = 3
0 Key = eventparams, value = target
1 Key = eventname, value = butnew_clicked
2 Key = target, value = butnew
Sub butnew_clicked(Tar as String)
-----------------------------------------------------
Going to page ChemicalStorePage
Disconnected
Websocket first connection
15 Dec. 2023 11:56 >>> Rob connected to ChemicalStorePage
15 Dec. 2023 11:56 >>> SELECT MAX(ID) FROM ChemStore;
[Ljava.lang.String;@7be58f16
[Ljava.lang.String;@7be58f16
Error occurred on line: 84
java.lang.NumberFormatException: For input string: "[Ljava.lang.String;@7be58f16"
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.debug.RDebugUtils.numberCast(RDebugUtils.java:43)
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 jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
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.debug.Debug.delegate(Debug.java:64)
at ef.EFPR.dbutils._nxtid(dbutils.java:353)
at ef.EFPR.chemicalstorepage._connectpage(chemicalstorepage.java:676)
at ef.EFPR.chemicalstorepage._websocket_connected(chemicalstorepage.java:1016)
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:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
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 anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:170)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
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 anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:65)
at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:21)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:119)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:170)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
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 ef.EFPR.main.main(main.java:29)
15 Dec. 2023 11:56 >>> $DbUtils.NxtID java.lang.Exception: java.lang.NumberFormatException: For input string: "[Ljava.lang.String;@7be58f16"
ChemicalStorePageee5125bb-e688-42cb-96d3-339cb668fb1f

When I look at MaxL I can see the correct value
Dump.png


Whats changed?
 
Top