This is pretty odd. I have a code module named "Globals". I use routines in it from several class objects. In fact one class object had already used it successfully, but when a second class object calls the same routine from it, I get the exception. The stack dump is:
In the case it works the debug call stack looks like
openorderheader.ToJSON - class instance
Globals.JSONValue - code module
serializableopenorder.ToJSON - class instance
Globals.JSONValue - code module
remotemethodcall.ToJSON - class instance
webapi.UploadOrders - class instance
main.btnCheckData - main activity
In the case it crashes the debug call stack (prior to crash) looks like
openorderline.ToJSON - class instance
Globals.JSONValue - code module
serializableopenorder.ToJSON - class instance
Globals.JSONValue - code module
remotemethodcall.ToJSON - class instance
webapi.UploadOrders - class instance
main.btnCheckData - main activity
Side note: Basically remotemethodcall, serializableopenorder, openorderheader, and openorderline are all classes, all implement a ToJSON method, each which call Globals.JSONValue. Globals.JSONValue may then obtain a class instance of a member and then call that classes ToJSON routine. Data is structured as a remotemethodcall has a member containing a list (call parameters), and that list contains an item holding a list of serializableopenorder. A serializableopenorder has a member containing a single openorderheader, and a list of openorderline. The total context is serializing the remotemethodcall instance, and therefore the recursion you see.
The ToJSON call in openorderline begins as
The failing line is
mp.Put("OrderNumber",Globals.JSONValue(mOrderNumber))
Try to step into this line and it stack dumps.
The running context is not that much different than when it ran similar code as the case that worked. In fact, it is within the very same call to serializableopenorder.ToJSON. That is what makes this so puzzling. So in concept this should work because the openorderheader.ToJSON works.
It consistently fails at the same place. I am mystified as to why this quit working for me. Scrambling to come up with an approach to diagnose this. Any ideas would be greatly appreciated.
B4X:
Error occurred on line: 286 (OpenOrderLine)
java.lang.NullPointerException
at anywheresoftware.b4a.B4AClass$ImplB4AClass.getActivityBA(B4AClass.java:20)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:882)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:831)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19270)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
In the case it works the debug call stack looks like
openorderheader.ToJSON - class instance
Globals.JSONValue - code module
serializableopenorder.ToJSON - class instance
Globals.JSONValue - code module
remotemethodcall.ToJSON - class instance
webapi.UploadOrders - class instance
main.btnCheckData - main activity
In the case it crashes the debug call stack (prior to crash) looks like
openorderline.ToJSON - class instance
Globals.JSONValue - code module
serializableopenorder.ToJSON - class instance
Globals.JSONValue - code module
remotemethodcall.ToJSON - class instance
webapi.UploadOrders - class instance
main.btnCheckData - main activity
Side note: Basically remotemethodcall, serializableopenorder, openorderheader, and openorderline are all classes, all implement a ToJSON method, each which call Globals.JSONValue. Globals.JSONValue may then obtain a class instance of a member and then call that classes ToJSON routine. Data is structured as a remotemethodcall has a member containing a list (call parameters), and that list contains an item holding a list of serializableopenorder. A serializableopenorder has a member containing a single openorderheader, and a list of openorderline. The total context is serializing the remotemethodcall instance, and therefore the recursion you see.
The ToJSON call in openorderline begins as
B4X:
Public Sub ToJSON As String
Dim mp As Map
mp.Initialize
mp.Put("OrderNumber",Globals.JSONValue(mOrderNumber))
mp.Put("LineNumber",Globals.JSONValue(mLineNumber))
mp.Put("ProductNumber",Globals.JSONValue(mProductNumber))
mp.Put("Description",Globals.JSONValue(mDescription))
mp.Put("QOO",Globals.JSONValue(mQOO))
mp.Put("QShip",Globals.JSONValue(mQShip))
mp.Put("QDelivered",Globals.JSONValue(mQDelivered))
The failing line is
mp.Put("OrderNumber",Globals.JSONValue(mOrderNumber))
Try to step into this line and it stack dumps.
The running context is not that much different than when it ran similar code as the case that worked. In fact, it is within the very same call to serializableopenorder.ToJSON. That is what makes this so puzzling. So in concept this should work because the openorderheader.ToJSON works.
It consistently fails at the same place. I am mystified as to why this quit working for me. Scrambling to come up with an approach to diagnose this. Any ideas would be greatly appreciated.
Last edited: