Android Question Troubles with custom type and File.ReadMap, File.WriteMap

Cadenzo

Active Member
Licensed User
Longtime User
I have a map with custom types. After saving and loading with next appstart the map is somehow not loaded correctly. Holding mouse over the map, the Name-Value View is not expandable, I see only this:
[btm=, [B]bezeichnung[/B]=fff, IsInitialized=true, preis=0.0, textfarbe=0, textsize=0]

and the error in the last line is: java.lang.RuntimeException: Field: bezeichnung not found in: java.lang.String

B4X:
Sub LoadImages
    lst_Buttonprops.Initialize
    'Return
    Dim sDir As String =  File.DirInternal
    Dim sFile As String = "productlist.dat"
    If File.Exists(sDir, sFile) Then
        lst_Buttonprops = File.ReadMap(sDir, sFile)
    End If
End Sub

Sub SaveImages
    Dim sDir As String =  File.DirInternal
    Dim sFile As String = "productlist.dat"
    File.WriteMap(sDir, sFile, lst_Buttonprops)
End Sub


Dim sKey As String = "Pos" & i
        If map.ContainsKey(sKey) Then
            Dim tPr As typProps' = lst.Get(i)
            tPr = map.Get(sKey)
            If tPr.bezeichnung <> "" Then btn.Text = tPr.bezeichnung
 

Cadenzo

Active Member
Licensed User
Longtime User
It seems that the result from map.Get(sKey) is a string like "[btm=, ...]" and can not be casted into a custom type. Any idea, what I am doing wrong?
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
The file content is:
#Sat Jun 16 22:59:43 MESZ 2018
Pos2=[bitmap\=typ_150.png, bezeichnung\=gfgf, IsInitialized\=true\n, preis\=3.5, textfarbe\=0, textsize\=26\n]

The type is defined in Main Process_Globals:
Type typProps(bezeichnung As String, preis As Float, textfarbe As Int, textsize As Int, bitmap As String)

B4X:
Dim map_Buttonprops As Map
'...
map_Buttonprops = File.ReadMap(sDir, sFile)
'...
File.WriteMap(sDir, sFile, map_Buttonprops)

But the map is not filled with the items of the type after loading.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Any idea, what I am doing wrong?
Method_636.png
File. WriteMap (Dir As String, FileName As String, Map As Map)

Creates a new file and writes the given map. Each key value pair is written as a single line.
All values are converted to strings.
 
Upvote 0
Top