Android Question B4XSerializator error

Kevin Hartin

Active Member
Licensed User
I am using the code from the Network Example at https://www.b4x.com/android/forum/t...-asyncstreams-b4xserializator.119011/#content to send instructions from one app to another.

The "message" consists of two strings; Action and Parameters which are then turned to bytes and appear to be sending OK.
CODE:
# SENDING APP
    Type MyMessage (Action As String, Parameters As String)

Private Sub btnRemote_Click
    Dim b As Button = Sender
    Dim mm As MyMessage
    mm.Initialize
    mm.Action = b.Tag
    mm.Parameters = ""
    If connected Then astream.Write(ser.ConvertObjectToBytes(mm))
End Sub

# RECEIVING APP    in B4X Class MediaPlayerPage 
    Type MyMessage (Action As String, Parameters As String)

Sub AStream_NewData (Buffer() As Byte)
    Log("Buffer.Length: "&Buffer.Length)            ### this seems to work and returns a length of 102
    Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer)            ### THE CRASH HAPPENS HERE Line 268'
...
End Sub

the Receiving app code is on is on a B4XPage called MediaPlayerPage that is added in B4XMainPage using;
Private MediaPlayer As MediaPlayerPage
B4XPages.AddPage("MediaPlayer",MediaPlayer)

I feel this has something to do with the issue as the error refers to b4xmainpage

When the app recieves the message it throws an error when I try to convert the buffer into an object.
error:
Buffer.Length: 102
Error occurred on line: 268 (MediaPlayerPage)
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.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 com.bookingmy.travel.mediaplayer.mediaplayerpage._astream_newdata(mediaplayerpage.java:116)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8633)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.b4xmainpage$_mymessage
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at java.lang.Class.forName(Class.java:379)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:583)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291)
    ... 18 more
Caused by: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.b4xmainpage$_mymessage
    ... 23 more

Again, any help is much appreciated...
Kev
 

Kevin Hartin

Active Member
Licensed User
I am using the code from the Network Example at https://www.b4x.com/android/forum/t...-asyncstreams-b4xserializator.119011/#content to send instructions from one app to another.

The "message" consists of two strings; Action and Parameters which are then turned to bytes and appear to be sending OK.
CODE:
# SENDING APP
    Type MyMessage (Action As String, Parameters As String)

Private Sub btnRemote_Click
    Dim b As Button = Sender
    Dim mm As MyMessage
    mm.Initialize
    mm.Action = b.Tag
    mm.Parameters = ""
    If connected Then astream.Write(ser.ConvertObjectToBytes(mm))
End Sub

# RECEIVING APP    in B4X Class MediaPlayerPage
    Type MyMessage (Action As String, Parameters As String)

Sub AStream_NewData (Buffer() As Byte)
    Log("Buffer.Length: "&Buffer.Length)            ### this seems to work and returns a length of 102
    Dim mm As MyMessage = ser.ConvertBytesToObject(Buffer)            ### THE CRASH HAPPENS HERE Line 268'
...
End Sub

the Receiving app code is on is on a B4XPage called MediaPlayerPage that is added in B4XMainPage using;
Private MediaPlayer As MediaPlayerPage
B4XPages.AddPage("MediaPlayer",MediaPlayer)

I feel this has something to do with the issue as the error refers to b4xmainpage

When the app recieves the message it throws an error when I try to convert the buffer into an object.
error:
Buffer.Length: 102
Error occurred on line: 268 (MediaPlayerPage)
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.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 com.bookingmy.travel.mediaplayer.mediaplayerpage._astream_newdata(mediaplayerpage.java:116)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:387)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:246)
    at android.app.ActivityThread.main(ActivityThread.java:8633)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.b4xmainpage$_mymessage
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    at java.lang.Class.forName(Class.java:379)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:583)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:291)
    ... 18 more
Caused by: java.lang.ClassNotFoundException: com.bookingmy.travel.mediaplayer.b4xmainpage$_mymessage
    ... 23 more

Again, any help is much appreciated...
Kev
Cancel that...

I moved the Type MyMessage (Action As String, Parameters As String) to the B4XMainPage and it works...

Thanks anyway,
Kev
 
Upvote 0
Top