Android Question Potential Map bug

atiaust

Active Member
Licensed User
Longtime User
I am having trouble using a map to store some data while reading a mysql data base table. There appears to be a bug while writing data to the map using map.put.

I have 27 records in a table. In a loop I read each record and add an Int value stored at position 4 in the record to the map.

Last part of the record read loop:
B4X:
'        vehicle capacity map - key Is capacity, Value = Vehicle ComboBox Index
            capacity = cursor.Getint2(4)
            capacityMap.Put(capacity,j)           
        Log("Capacity = "&cursor.GetInt2(4))   
            j = j + 1
        Loop   
    cursor.Close

Capacity = 13
Capacity = 8
Capacity = 5
Capacity = 13
Capacity = 13
Capacity = 11
Capacity = 21
Capacity = 7
Capacity = 11
Capacity = 11
Capacity = 25
Capacity = 11
Capacity = 11
Capacity = 11
Capacity = 11
Capacity = 11
Capacity = 13
Capacity = 11
Capacity = 13
Capacity = 11
Capacity = 13
Capacity = 25
Capacity = 22
Capacity = 14
Capacity = 4
Capacity = 12
Capacity = 13

To check the contents of the map
B4X:
    For i = 1 To capacityMap.Size - 1
        LogDebug("Capacity = "&capacityMap.Get(i))
    Next

Capacity = null
Capacity = null
Capacity = null
Capacity = 24
Capacity = 2
Capacity = null
Capacity = 7
Capacity = 1
Capacity = null
Capacity = null

As above only 12 items are added to the map and all vales are incorrect.
If I swap capacityMap.Put(capacity,j) to read capacityMap.Put(j,capacity) then the values stored in the map are correct with 27 items in the map.
 
Top