Please take a look in these two pictures. List size is 3 but it throws the same error with two different methods...
B4X:
Dim i As Int
Log(RecentStoreList.Size) ' Size is 3
Dim Ubound As Int = RecentStoreList.Size - 1
For i = 0 To Ubound
Log(GetType(RecentStoreList.Get(i))) ' Throws Size is 2
Dim mpcust As Map = RecentStoreList.Get(i)
...
Same...
B4X:
For Each mpcust As Map In RecentStoreList
If mpcust.GetDefault("server", "") = Item.Server Then ' Throws Size is 2
RecentStoreList.RemoveAt(RecentStoreList.IndexOf(mpcust))
End If
Next
Dim Ubound As Int = RecentStoreList.Size - 1
For i = 0 To Ubound
The upper limit is evaluated once anyway.
You are modifying the list inside the loop so its actual size changed.
Correct code:
B4X:
Dim i As Int = 0
Do While i < RecentStoreList.Size
Dim mpcust As Map = RecentStoreList.Get(i)
If mpcust.GetDefault("server", "") = Item.Server Then
RecentStoreList.RemoveAt(i)
i = i - 1
End If
i = i + 1
Loop
For i = RecentStoreList.Size - 1 To 0 Step -1
Dim mpcust As Map = RecentStoreList.Get(i)
If mpcust.GetDefault("server", "") = Item.Server Then
RecentStoreList.RemoveAt(i)
End If
Loop