Android Question [B4X] Network + AsyncStreams + B4XSerializator

Adrian Jansen

Member
Licensed User
Longtime User
Hi All,
I am trying to get this example Erel posted some time ago.
Using B4A Version 13.10 and B4J version 10.30 on Windows 11 Java version jdk-19.0.2 on both devices

Sucessfully opened the ports in Windows Firewall

Transfer from PC > Android Phone running the example code seems to work ok for both text and the pretty bitmap works.
But transfers the other way, from Phone to PC always fails with a pile of Java errors. Error log from the PC below:

Waiting for debugger to connect...
Program started.
Trying to connect to: 192.168.1.189
Error occurred on line: 82 (Main)
java.lang.RuntimeException: java.lang.ClassNotFoundException: b4j.example.b4xmainpage$_mymessage
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:314)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:374)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:129)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:99)
at b4j.example.main._astream_newdata(main.java:285)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
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.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA$2.run(BA.java:250)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
at java.base/java.lang.Thread.run(Thread.java:1589)
Caused by: java.lang.ClassNotFoundException: b4j.example.b4xmainpage$_mymessage
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:390)
at java.base/java.lang.Class.forName(Class.java:381)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:547)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291)
... 21 more

Line 82 in the B4J code is:
Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer)

Since I know nothing about Java, this does not help me much. I presume there is something simple like a missing library, but I cant see where
I have the RandomAccessFile library and Network libraries both ticked in the library manager.

Any suggestions welcome
 

Adrian Jansen

Member
Licensed User
Longtime User
Thanks for the quick response

Yes, in the B4J Main module Process Globals:

Type MyMessage (Name As String, Age As Int, Image() As Byte)

and its used in
Sub AStream_NewData (Buffer() As Byte)
Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer)

edtAge.Text = mm.Age
edtName.Text = mm.Name

The only change I have made to the B4J code is to change the port number to 51042, the same as what the B4A code uses, then in Windows Firewall I opened the port 51042 for both input and output. I did try changing this back to port 10000 in B4J and added that to the firewall for input, but that still created the same errors.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
The only change I have made to the B4J code is to change the port number to 51042, the same as what the B4A code uses, then in Windows Firewall I opened the port 51042 for both input and output. I did try changing this back to port 10000 in B4J and added that to the firewall for input, but that still created the same errors.
What happen when you don't change anything and run the projects?
 
Upvote 0

Adrian Jansen

Member
Licensed User
Longtime User
Aeric:
Thats what I started with, but could not get it to work, thats why I started fooling with ports, since it seemed to be a comms problem.

Walt61:
Ah! did that, and it worked ! Thanks for that.
Now I can get on and see if I can send a CSV string array....
 
Upvote 0
Top