Hi everyone,
I'm using MQTT to get messages from The Things Network from two sensors. I then put them into a map which works perfectly fine - usually.
For some reason, two days ago my program crashed and sent me an error message saying my map wasn't initialized. I basically ignored it, but now it came up again. Has anyone got an idea what I can do to avoid this?
EDIT: The program both times had run for several minutes and received several messages from the network before crashing
Error message:
(Map) Not initialized
Error in line: 279 (Main)
java.lang.RuntimeException: Object should first be initialized (Map).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:67)
at b4j.example.main._mqtt_messagearrived(main.java:1230)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94)
at anywheresoftware.b4a.BA$3.run(BA.java:246)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
I'm using MQTT to get messages from The Things Network from two sensors. I then put them into a map which works perfectly fine - usually.
For some reason, two days ago my program crashed and sent me an error message saying my map wasn't initialized. I basically ignored it, but now it came up again. Has anyone got an idea what I can do to avoid this?
EDIT: The program both times had run for several minutes and received several messages from the network before crashing
B4X:
Sub mqtt_MessageArrived (mqtttopic As String, Payload() As Byte)
Log(BytesToString(Payload, 0, Payload.Length, "utf8"))
JSON.Initialize(BytesToString(Payload, 0, Payload.Length, "utf8"))
Map1 = JSON.NextObject
m.Initialize
m = Map1.Get("payload_fields")
Log(m)
moisture = m.Get("moisture")
temp = m.Get("temperature")
Log(Round2(moisture,1))
Log(Round2(temp,1))
End Sub
Error message:
(Map) Not initialized
Error in line: 279 (Main)
java.lang.RuntimeException: Object should first be initialized (Map).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:32)
at anywheresoftware.b4a.objects.collections.Map.Get(Map.java:67)
at b4j.example.main._mqtt_messagearrived(main.java:1230)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:625)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:168)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:94)
at anywheresoftware.b4a.BA$3.run(BA.java:246)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)