Because of the sorting advantages of a B4XOrderedMap, I'm converting my existing Map objects to B4XOrderedMap. The conversion itself is pretty straightforward. But I run into trouble when I try to save the B4XOrderedMap as an object in a KeyValueStore (v2.30).
Here's typical code for saving my Map objects to KeyValueStore, which works fine:
... and here's the converted code which results in a crash:
This is what the Debugger Log shows when it crashes:
It looks to me like KeyValueStore isn't compatible (yet?) with B4XOrderedMap. Or am I leaving out some necessary code?
Here's typical code for saving my Map objects to KeyValueStore, which works fine:
Map to KeyValueStore, working fine:
'(Process_Globals)
Type TRIP_DATA(id_trip As String,fid As String,wpid_start As String,wpid_dest As String,dist As Float, _
ticks_start As Long,ticks_end As Long,size As Int,paused As Boolean)
Dim mpTrips As Map
Dim kvs_t As KeyValueStore
'(typical code)
mpTrips.Initialize
Dim trip As TRIP_DATA
trip.Initialize
mpTrips.Put("tripkey",trip)
kvs_t.Initialize(SafeDir,MainDir & "/*TRIPS")
kvs_t.Put("mpTrips",mpTrips)
kvs_t.Close
... ... ...
B4XOrderedMap to KeyValueStore, CRASHES:
'(Process_Globals)
Type TRIP_DATA(id_trip As String,fid As String,wpid_start As String,wpid_dest As String,dist As Float, _
ticks_start As Long,ticks_end As Long,size As Int,paused As Boolean)
Dim mpTrips As B4XOrderedMap
'(typical code)
mpTrips=B4XCollections.CreateOrderedMap
'mpTrips.Initialize '(crashes whether this line is included or not)
Dim kvs_t As KeyValueStore
Dim trip As TRIP_DATA
trip.Initialize
mpTrips.Put("tripkey",trip)
kvs_t.Initialize(SafeDir,MainDir & "/*TRIPS")
kvs_t.Put("mpTrips",mpTrips) '<<<<<<< this results in a CRASH!
kvs_t.Close
... ... ...
Error occurred on line: 18 (KeyValueStore)
java.lang.RuntimeException: Cannot serialize object: [b4xcollections=null, general=null, httputils2service=null
, list=(ArrayList) [test], main=null, map=(MyMap) {test=[IsInitialized=true, dist=0.0, fid=
, id_trip=, paused=false, size=0
, ticks_end=0, ticks_start=0, wpid_dest=
, wpid_start=]}
It looks to me like KeyValueStore isn't compatible (yet?) with B4XOrderedMap. Or am I leaving out some necessary code?