Android Question [Solved]Cannot serialize object

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Hello, I have a problem when sending a serialized object.
Here I attach the example.
Thank you

Johan Hormaza
 

Attachments

  • PCL_Bluetooth_B4A.zip
    14.8 KB · Views: 192

William Lancee

Well-Known Member
Licensed User
Longtime User
I looked your project. It is far too complicated to decipher for me, and probably for many others.
You also didn't specify what your problem is.

Describe your problem and create a simple example project that shows the problem.
If you do that, then I and others will be willing to help.
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Too bad, it was already quite late at night in my country.
What I want is to send a data packet via Bluetooth already serialized. This is where I send the package:
B4X:
Private Sub btnTransaction_Click
    Try
        Main.DatafonoPCL.WriteBytes(ser.ConvertObjectToBytes(DoTrans(DoTransaction))) 'problem is here
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub DoTrans(DoTran As DoTransactionTask) As Object()
    Return Array(DoTran.transIn1,DoTran.transOut1)
End Sub

This is the package that contains an object of class TransactionIn and another TransactionOut. In which they already have their values.

B4X:
Type DoTransactionTask(transIn1 As TransactionIn, transOut1 As TransactionOut)
    Private DoTransaction As DoTransactionTask
    Private transIn As TransactionIn
    Private transOut As TransactionOut
    Private Sub B4XPage_Created (Root1 As B4XView)
    transOut.Initialize
    transOut.cAmount(0) = 0
    transOut.cNumAuto(0) = 0
    transOut.cCardEndValidityDate(0) = 0
    transOut.cCmc7(0) = 0
    transOut.cIso2(0) = 0
    transOut.cPan(0) = 0
    transOut.cCurrencyCode(0) = 0
    transOut.cC3Error(0) = 0
    transOut.cNumTerm(0) = 0
    transOut.cUserData1(0) = 0
    
    transIn.Initialize
    transIn.setAmount("20000")
    transIn.setCurrencyCode("978")
    transIn.setOperation("978")
    transIn.setTermNum("58")
    transIn.setAuthorizationType("2")
    transIn.setCtrlCheque("2")
    transIn.setUserData1("Johan Hormaza")
    
    DoTransaction.Initialize
    DoTransaction.transIn1 = transIn
    DoTransaction.transOut1 = transOut
    End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
No problem with the time difference, it trips me up all the time. Sometimes it seems that everybody is online all the time.

Serializer does not do arrays of objects ( HERE).

B4X:
Array(DoTran.transIn1,DoTran.transOut1)
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
Before pressing the Transaction button you must first connect to a Bluetooth device

B4X:
Error occurred on line: 96 (B4XMainPage)
java.lang.RuntimeException: Cannot serialize object: [b4xcollections=null, b4xpages=null, camount=[B@fd2073b
, camount2=[B@d433e58, cautotype=[B@2b08bb1, ccashnum=[B@ba19896
, ccmc7=[B@a4fdc17, ccryptovad=[B@9d9e804, cctrlcheque=[B@d9131ed
, ccurrencycode=[B@e56a822, ccurrencycode2=[B@e6c22b3, ccustomerpresent=[B@f8070
, cdatefinvalidite=[B@65bffe9, cdateinitvalidite=[B@45b246e, cidentcheque=[B@afc370f
, ciso2=[B@ac4339c, cnumauto=[B@3ebb1a5, cnumcontexte=[B@619197a
, cnumdossier=[B@ccf352b, cnumticket=[B@aeed88, coperation=[B@60ac321
, coption=[B@68f5346, cpan=[B@489f907, creadertype=[B@b095a34
, ctendertype=[B@4af705d, ctermnum=[B@7dd5dd2, ctrnsnum=[B@e431ea3
, ctutorialmode=[B@afbe5a0, ctypefacture=[B@6f7b559, cuserdata1=[B@c8f851e
, cuserdata2=[B@6df01ff, ffu=[B@9c9bbcc, main=null
, starter=null]
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeList(B4XSerializator.java:269)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:237)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121)
    at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79)
    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.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7297)
    at android.view.View.performClickInternal(View.java:7274)
    at android.view.View.access$3600(View.java:819)
    at android.view.View$PerformClick.run(View.java:28017)
    at android.os.Handler.handleCallback(Handler.java:914)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7564)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
** Activity (main) Pause event (activity is not paused). **
** Service (starter) Destroy (ignored)**
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
No problem with the time difference, it trips me up all the time. Sometimes it seems that everybody is online all the time.

Serializer does not do arrays of objects ( HERE).

B4X:
Array(DoTran.transIn1,DoTran.transOut1)
What do you mean?
If I use
1650208904749.png
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
You seem to be trying to serialize class instances of TransactionIn and ttransactionOut which I don't think B4XSerializator supports. It can only serialize certain types of objects. See the splash screen here
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
You can serialize custom types but they cannot hold class intances.
And what do you recommend I do with the TransactionIn and TransactionOut classes to be able to enter them into a Type DoTransactionTask (transIn1 As TransactionIn, transOut1 As TransactionOut)?
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
You seem to be trying to serialize class instances of TransactionIn and ttransactionOut which I don't think B4XSerializator supports. It can only serialize certain types of objects. See the splash screen here
Thanks friend, I based myself precisely on this example ?
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
It depends on all kinds of things. Making them custom types is a good option.
Thanks Erel, you mean that they are not classes but Type? Something like that?
B4X:
    Type TransactionIn(...)
    Type TransactionOut(...)
    Type DoTransactionTask(transIn1 As TransactionIn, transOut1 As TransactionOut)
 
Upvote 0
Top