Problem with ReadList function

TheDevMan

Member
Licensed User
Longtime User
When i save for example the whole SMS messages as a list and write that to file, that works ok.

But, When you read the file with ReadList and try to connect that one with a SMS object, it comes with an exception : Java.string

sample code (not full):

Dim listSms As List
Dim i As Int

listsms.Initialize
listSms = File.ReadList(File.DirRootExternal,"sms.dat")

For i = 0 To Listsms.Size - 1

Dim Sd As Sms
Sd = ListSms.Get(i) <---- Here it wil Crash!
Log(sd)


Is this a bug?
 

kickaha

Well-Known Member
Licensed User
Longtime User
File.ReadList converts everything to strings, so the list is no longer a list of sms objects.

You can read and write lists preserving the format with RandomAccessFile.ReadObject and WriteObject.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You will not be able to use WriteObject with SMS objects. The following types of objects are supported: primitives, list, map, arrays, user custom types and java types that implement the serializable interface. SMS object is not one of those. You will need to manually write it and read it. One simple way will be to convert the message to a Map and then write the map with WriteObject.
 

TheDevMan

Member
Licensed User
Longtime User
Ok, Thanks all for your reply.

I thought when you use the function Readlist, the object LIST will be filled correctly the same as when i saved it. Otherwise it has no use the function "Readlist".


But if i cant write SMS objects, Can i do : Sms = ObjectWritedList

My 2 cents :)
 
Last edited:
Top