title: How do I loop over a HashMap after retrieving Firebase data?
body: <p>I'm working in Android Studio, and retrieving the following data from Firebase:</p>
  
  <pre><code>coloursets:
     default:
        name: "Default colour set"
        description: "Default set of colours"
        colours:
            white:
               red: 255
               green: 255
               blue: 255
               name: "white"
            black:
               red: 0
               green: 0
               blue: 0
               name: "black"
  </code></pre>
  
  <p>I'm retrieving it like this:</p>
  
  <pre><code>public void initialiseColourSet(ValueEventListener listener) {
  
      if(this.key == null) return;
  
  DatabaseReference mColourSetReference = FirebaseDatabase.getInstance().getReference()
          .child("coloursets").child(this.key);
  
  mColourSetReference.addListenerForSingleValueEvent(listener);
  }
  </code></pre>
  
  <p>where "key" is set to "default", and "listener" is:</p>
  
  <pre><code>new ValueEventListener() {
  
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
         ArrayList&lt;ChartColour&gt; colourList= new ArrayList&lt;&gt;();
         Map&lt;String, HashMap&gt; objectMap = (HashMap&lt;String, HashMap&gt;) dataSnapshot.getValue();
  
         // SOMETHING NEEDS TO GO HERE - SEE BELOW
  
         }
  
  }
  </code></pre>
  
  <p>The ColourSet class has the following:</p>
  
  <pre><code>String key, name, description;
  ArrayList&lt;ChartColour&gt; colours = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>So, I want to loop over 'objectMap' to get the colourSet name and description, and then get the list of colours into the local variable colourList, which is then used to set 'colours' in the ColourSet object.</p>
  
  <p>I just can't get the loop correct in listener.  I've looked up lots of answers, but none seem to quite apply to my case.</p>
  
  <p>Currently I have the following in listener:</p>
  
  <pre><code>new ValueEventListener() {
  
     @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      ArrayList&lt;ChartColour&gt; colourList= new ArrayList&lt;&gt;();
      Map&lt;String, HashMap&gt; objectMap = (HashMap&lt;String, HashMap&gt;) dataSnapshot.getValue();
       for (Map.Entry&lt;String, HashMap&gt; entry : objectMap.entrySet()) {
         switch (entry.getKey()) {
           case "name":
             mColourSet.setName(String.valueOf(entry.getValue()));
             break;
           case "description":
             mColourSet.setDescription(String.valueOf(entry.getValue()));
             break;
           case "colours":
             // Need some kind of FOR LOOP here
               ChartColour colour = new ChartColour();
               /*
                  colour.setKey(??);
                  colour.setName(??);
                  colour.setRed(??);
                     ... etc ... */
                  colourList.add(colour);
             // END OF FOR LOOP
             mColourSet.setColours(colourList);
         }
       }
     }
  });
  </code></pre>
  
  <p>So, I'm just not sure what I need to put in the FOR loop in the listener, in order to loop over the colours. Everything I've tried so far just gives me the wiggly red line, without any explanation of what's wrong.</p>