B4J Question [SOLVED] Cannot initialize B4XBytesBuilder in NONUI app

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

I can Initialize B4XBytesBuilder in UI apps, but here for some strange reasons the inizializer line return an error on NONUI (Server) app:
B4X:
Dim bBuilder As B4XBytesBuilder
bBuilder.Initialize ' <-- ERROR HERE
bBuilder.Clear
the log show an IllegalArgumentException, wrong number of arguments.
Can someone help me to know because this happen ?
Thanks

Log:
Waiting for debugger to connect...
Program started.
b4j.example.b4xbytesbuilder:_initialize, [[mbuffer=null, mlength=0, b4xcollections=null
], anywheresoftware.b4a.shell.ShellBA@3532ec19]
Error occurred on line: 6 (B4XBytesBuilder)
java.lang.IllegalArgumentException: wrong number of arguments
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:629)
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:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.main(main.java:30)
 

Daestrum

Expert
Licensed User
Longtime User
Just tried it in a server app, no error messages at all.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks for reply @Daestrum , do you mean NONUI app ?
I have error here, not while compile, while execute it.
I tried it in Debug mode.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
You are perfectly right, this in a new NONUI project works to me too:
B4X:
Sub Process_Globals
    Private bBuilder As B4XBytesBuilder
End Sub

Sub AppStart (Args() As String)
    bBuilder.Initialize
    bBuilder.Clear
   
    Log("PASSED")
   
    StartMessageLoop
End Sub

But for same strange reasons it will not works on my main project.

May some incompatibility with other libraries ?
Now I will start to try importing all libraries like in my main project, recompile and execute again...
Some tips?

Thanks
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
One thing I did notice, although it gave no error message, if you place the initialise after the StartMessageLoop it doesn't appear to initialise the b4xbytesbuilder.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks both @Erel and @Daestrum for replies,

Probably I've found a mistake, this seem related to one my class that I compiled as library with old B4J release.

I found it by starting from a blank project, then add one by one the libraries I've used in main project, eveey time I add a library, I execute it again. This may can useful for peoples that had the same problem.

Now I recompiled my class and the error in the B4XByteBuilder initializer disappeared.

This class I recompiled is an Encryption class I wrote to exchange data (over socket) to/from Android, ESP32 and Raspberry, I had a lot of difficulties making it to work because different encoding on B4X and C++, finally after I wrote a lots of non working subs to encode/decode, I just end up to shift some characters that is not a true encryption. But this is another question, eventually I will start a new thread to discuss it.

Thanks again, I will put SOLVED in the thread title.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
One thing I did notice, although it gave no error message, if you place the initialise after the StartMessageLoop it doesn't appear to initialise the b4xbytesbuilder.
The initializer is before of StartMessageLoop that is just the last line in the App Start sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
if you place the initialise after the StartMessageLoop it doesn't appear to initialise the b4xbytesbuilder.
The code execution stops once it reaches the StartMessageLoop. The meaning of this call is that the thread starts a message loop. Messages = events. It only exits the message loop after a call to StopMessageLoop (which actually sends a message to the messages queue).
 
Upvote 0
Top