Android Question StringArrayToList Type Mismatch String Rank Issue?

Tim Chapman

Active Member
Licensed User
Longtime User
Attached is a picture showing the code (line 284) and the error text in the upper right of the screenshot.

I am happy to upload code, etc. if needed, but this allowed me to show the complete text of the error.

The StringArrayToList returns a list. Please tell me what I am doing wrong in my code. I am setting it = to a variable declared as a list type. Not sure what I am missing here.

Thanks again for assistance.
 

Attachments

  • error.jpg
    error.jpg
    289.8 KB · Views: 213

Tim Chapman

Active Member
Licensed User
Longtime User
The code is:
B4X:
Sub PopulateMySpellBook(ListOfMaps As List, HeaderList As List, MySpellJustificationMap As Map)
    Dim LoadDir As String : LoadDir = File.DirRootExternal & "/dnd"
    Dim BackupDir As String : BackupDir = File.DirRootExternal & "/dnd"
    Dim FileName As String

    Log("Started Spellbook")
   
    FileName = "MySpellBook.csv"
    If File.Exists(LoadDir, FileName) Then            'If MySpellBook exists, load it.

        'Load MySpellBook list.
        LoadCSVFromFile(LoadDir, FileName, MySpellBookListOfMaps, MySpellBookListHeader, MySpellBookJustificationMap)

    Else     'Load the big spell list, My Classes list and populate MySpellBook.
        Dim BigSpellsListOfMaps As List : BigSpellsListOfMaps.Initialize()
        Dim BigSpellsListHeader As List : BigSpellsListHeader.Initialize()
        Dim BigSpellsJustificationMap As Map : BigSpellsJustificationMap.Initialize()
        Dim BigClassesListOfMaps As List : BigClassesListOfMaps.Initialize()
        Dim C As Int
        Dim MyClasses(MyClassesListOfMaps.Size) As String
        Dim RowMap As Map : RowMap.Initialize
        Dim ClassCounter As Int
        Dim AClassSpellsLevelsMap As Map : AClassSpellsLevelsMap.Initialize
        Dim SpellName As String
        Dim Level As Int
        Dim Class As String
        Dim LevelAll As String
        Dim ClassesWithSpellsAndLevelsMap As Map : ClassesWithSpellsAndLevelsMap.Initialize
        Dim TempMap As Map : TempMap.Initialize
        Dim sf As StringFunctions : sf.Initialize
        Dim SpellwithClassesAndLevelsMap As Map : SpellwithClassesAndLevelsMap.Initialize
        Dim su As StringUtils
       
        'Load the Big Spell List. It has all the spells for all the classes.
        FileName = "BigSpellsList.csv"
        LoadCSVFromFile(LoadDir, FileName, BigSpellsListOfMaps, BigSpellsListHeader, BigSpellsJustificationMap)
       
        'Create spellclasseslevels.csv
        FileName = "spellclasseslevels.csv"
        If File.Exists(LoadDir, FileName) = False Then
            For i = 1 To BigSpellsListOfMaps.Size - 1    'Iterate through BigSpellsListOfMaps
                Dim TempMap As Map : TempMap.Initialize   
                TempMap = BigSpellsListOfMaps.Get(i)    'Get one line from BigSpellsListOfMaps.  This is a map containing one spell and all its fields.
                LevelAll = TempMap.Get("Level All")        'Get the contents of the Level All field from the map.
                Log("LevelAll = " & LevelAll)
                Dim OneClassAndLevel As List : OneClassAndLevel.Initialize
                OneClassAndLevel = sf.StringArrayToList(LevelAll,False,False)
                'Log("OneClassAndLevel" & OneClassAndLevel)
'                For Each OneClassAndLevel As String In LevelAll
'                    Class = sf.Left(OneClassAndLevel,sf.Len(OneClassAndLevel)-2)
'                    Level = sf.Right(OneClassAndLevel,1)
'                    SpellName = TempMap.Get("Title")
'                    SpellwithClassesAndLevelsMap.Put(Class, Level)
'                Next
                SpellwithClassesAndLevelsMap.Put("SpellName", SpellName)
                SpellsClassLevelsList.Add(SpellwithClassesAndLevelsMap)
            Next
            su.SaveCSV(LoadDir, FileName , "," , SpellsClassLevelsList)
        End If

The error occurs on the 13th line from the bottom which starts with OneClassAndLevel =

The error is:

Cannot cast type: {Type=String,Rank=0, RemoteObject=True} to {Type=String,Rank=1, RemoteObject=True} warning 22.

This error happens on the first iteration of the code.
The commented out lines below the line in question were how I was solving the problem of parsing the list before without success. They will be changed.

This is the log showing what LevelAll contains:

LevelAll = Artificer 3, Cyre Scout 3
Warning: same object added to list multiple times.
LevelAll = Artificer 2
Warning: same object added to list multiple times.
LevelAll = Anagakok 8, Beholder Mage 8, Deathwalker 8, Fleshcrafter 8, Sha'ir 8, Sorcerer 8, Wizard 8, Soul Reaper 8, Sublime Chord 8

Thanks again for assistance!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I recommend you to remove StringFunctions library. You can do everything without it.

What is the signature of sf.StringArrayToList? Based on its name I guess that it expects an array of strings. You are passing a string instead.

Another tip: use a custom type to hold all the information you need and save all the data (can be a list of these types) to a file with RandomAccessFile.WriteB4XObject.
 
Upvote 0

Tim Chapman

Active Member
Licensed User
Longtime User
Hi Erel,
I wanted to reply as to why I did not use custom types and save as random access files. I want to be able to use human readable/editable text files. That is why I chose CSV files and the approach I am using with lists of maps. Thank you again for your assistance on my project.
 
Upvote 0
Top