B4J Question How can I understand a B4j error?

fabton1963

Member
Licensed User
Longtime User
Good morning, everyone,

From the log of my application, the following errors are starting to emerge, which are causing the program to crash.
error1:
main._appstart (java line: 450)
java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "null"
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA$3.run(BA.java:267)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
    at ElmacECL.mqttbridge.main._appstart(main.java:450)
    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:111)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at ElmacECL.mqttbridge.main.main(main.java:34)
Caused by: java.lang.NumberFormatException: For input string: "null"
    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:434)
    at ElmacECL.mqttbridge.main._mqtt_main_messagearrived(main.java:3907)
    at jdk.internal.reflect.GeneratedMethodAccessor2.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:111)
    ... 12 more

main.main (java line: 34)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "null"
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at ElmacECL.mqttbridge.main.main(main.java:34)
Caused by: java.lang.RuntimeException: java.lang.NumberFormatException: For input string: "null"
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:140)
    at anywheresoftware.b4a.BA$3.run(BA.java:267)
    at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
    at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
    at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
    at ElmacECL.mqttbridge.main._appstart(main.java:450)
    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:111)
    ... 2 more
Caused by: java.lang.NumberFormatException: For input string: "null"
    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:434)
    at ElmacECL.mqttbridge.main._mqtt_main_messagearrived(main.java:3907)
    at jdk.internal.reflect.GeneratedMethodAccessor2.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:111)
    ... 12 more
It seems that the error is due to "null" being assigned to a numeric variable, but I can't figure out on which line of my code this assignment is happening. Could it be an error within the MQTT library?

Please help me decode the error message.
 

jmon

Well-Known Member
Licensed User
Longtime User
B4X:
java.base/java.lang.Double.parseDouble(Double.java:543)
    at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:434)
    at ElmacECL.mqttbridge.main._mqtt_main_messagearrived(main.java:3907)

Looks like that in main/mqtt_main_messagearrived, you're trying to assign a value to a Double variable, but the value is 'null' (it's not a number).

Read your errors from bottom to top, where the bottom is what lead to your error chronologically.
 
Upvote 0

fabton1963

Member
Licensed User
Longtime User
B4X:
java.base/java.lang.Double.parseDouble(Double.java:543)
    at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:434)
    at ElmacECL.mqttbridge.main._mqtt_main_messagearrived(main.java:3907)

Looks like that in main/mqtt_main_messagearrived, you're trying to assign a value to a Double variable, but the value is 'null' (it's not a number).

Read your errors from bottom to top, where the bottom is what lead to your error chronologically.
Thanks, I'll try to log all payloads and check the sub mqtt_main_messagearrived.
 
Upvote 0

fabton1963

Member
Licensed User
Longtime User
Your input string is null (nothing). Run in debug mode and see on what line of your b4j project the crash occurs. Without a sample project it is just about impossible to help you.
Of course in staging enviroment using debug mode all works good, the trouble is in production with thousand of messages running in my mosquitto broker :( .
I'll try the jmon's advice.
 
Upvote 0

fabton1963

Member
Licensed User
Longtime User
Solved, the error was inside ElmacECL.mqttbridge.main._mqtt_main_messagearrived cused by a missing null check in my code,
but the null value was assigned to a var declared as int not double so the first time I cheched only assigment to double.
 
Upvote 0
Top