title: Java: Local variable mi defined in an enclosing scope must be final or effectively final
body: <p>I get the error, as in subject, and I kindly ask you how to repair it...
  ERROR is in menuItem-loop, where I try to set the textArea foreground colour to one picked from menuItem: (colors[mi])</p>
  
  <pre><code>    String[] colors = {
              "blue", 
              "yellow",
              "orange",
              "red", 
              "white", 
              "black", 
              "green", 
              };
  
  JMenu mnForeground = new JMenu("Foreground");
              for (int mi=0; mi&lt;colors.length; mi++){
                  String pos = Character.toUpperCase(colors[mi].charAt(0)) + colors[mi].substring(1);
                  JMenuItem Jmi =new JMenuItem(pos);
                  Jmi.setIcon(new IconA(colors[mi]));
  
                  Jmi.addActionListener(new ActionListener() {
                      @Override
                      public void actionPerformed(ActionEvent e) {
                          JMenuItem item = (JMenuItem) e.getSource();
                          IconA icon = (IconA) item.getIcon();
                          Color kolorIkony = getColour(colors[mi]); // ERROR HERE: (colors[mi])
                          textArea.setForeground(kolorIkony);
                      }
                  });
  
                  mnForeground.add(Jmi);
              }
  
  public Color getColour(String colour){
    try {
        kolor = Color.decode(colour);
    } catch (Exception e) {
        kolor = null; 
    }
    try {
          final Field f = Color.class.getField(colour);
          kolor = (Color) f.get(null);
        } catch (Exception ce) {
          kolor = Color.black;
        }
  return kolor;
  }
  </code></pre>