B4J Question ConvertObjectToBytes (why does this give a java error?)

Marc De Loose

Member
Licensed User
Longtime User
The First gives no error but if change the code to the last it gives a Java Error.
I am confused.

B4X:
'===========> this gives NO ERROR
        For i=1 To All_lst_xRotateKnobs.Size-1
            Private ToAdd As xRotateKnobsCollectionType_NEW = All_lst_xRotateKnobs.Get(i)
            testlist.Add(ToAdd)
        Next

        ObjBytes =  ser.ConvertObjectToBytes(testlist)
        
'===========>' this does give JAVA ERROR object should first be initialized (list)       
        ObjBytes =  ser.ConvertObjectToBytes(All_lst_xRotateKnobs)
 

Marc De Loose

Member
Licensed User
Longtime User
1. Please post the full error message from the logs.

2. What is the output of Log(All_lst_xRotateKnobs)?

3. Note that the working code skips the first element.
To avoid such errors:
B4X:
For Each ToAdd As xRotateKnobsCollectionType_NEW  In All_lst_xRotateKnobs
 testlist.Add(ToAdd)
Next
Because of your question I looked at the logs and realized I had a bug somewhere that did not initialize a list that was part of the first element . I corrected that and now it passes.

To answer your question 3. The first element should be skipped by design. (I know that in the failing code it is included but that will be handled when reloading ).

Thx for activating my thoughts. :)
 
Upvote 0
Top