Android Question Problem - Map.Get()

Harris

Expert
Licensed User
Longtime User
The following sub attempts to get a value of Map from the RuleSet map.
The commented line returns "Map not Intialized" (' mr = RuleSet.Get(DefCM.CLogRule))

The For..Next block returns the map correctly.

Both return the value as object (Get and GetValueAt). Can''t see what is wrong?

B4X:
Sub GetCycleDays As Int
    Dim mr As Map
    Dim b As Boolean
    Dim res,i,ky As Int

    mr.Initialize
'     mr = RuleSet.Get(DefCM.CLogRule)
    For i = 0 To RuleSet.Size -1
      ky = RuleSet.GetKeyAt(i) 
      If ky = DefCM.CLogRule Then
         mr = RuleSet.GetValueAt(i)
         Exit
      End If    
    Next

    Log(" returned map: "&mr)
    b = mr.Get("cycle_max_on")
    If b = True Then
       res = mr.Get("cycle_max_onv")
    Else
       res = 0
    End If
    Return res
End Sub
 

barx

Well-Known Member
Licensed User
Longtime User
What is
DefCM.CLogRule ?

Or more to the point what is the object type of the value within the RuleSet with the key returned by DefCM.CLogRule??

RuleSet is a Map which is why the for loop works, If the object type of the value in the RuleSet Map that has a key of whatever DefCM.CLogRule signifies is not a Map object, then you will get that error.

Hope that makes sense
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
DefCM.ClogRule is an int (4).
It is the key of RuleSet Map of which the values are stored maps.

The loop checks to see if DefCM.LogRule var equals the key stored in RuleSet. (4 = 4)
When it succeeds it returns the map object.

I just thought map.get(key) would return the map object since GetValueAt(index) appears to be just another way of achieving the same goal.

Thanks Barx. Whatever works...
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
With Map.Get you name the key.
With Map.GetValueAt you state the position index in the map
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
What is RuleSet ???
I think that the error is because RuleSet is not initialize

Sergio
 
Upvote 0
Top