title: NullPointerException from trying to get separate RGB components
body: <p>I am trying to get the separate RGB components from each element in a 2D color array,but it keeps throwing a NullPointerException and I am not sure why.</p>
  
  <p>CODE:       </p>
  
  <pre><code>    Color[][] grid = new Color[MaxColors][MaxColors];
  
      int R1 = 0;
  
  
      for(int x = 0; x &lt; N; x++){
          for(int y = 0; y &lt; N; y++){
  
  
              R1 = grid[x][y].getRed(); 
              /* do something with R1*/
  
  
  
          }
      }
  </code></pre>
  
  <p>I also tried to first add the colors to a list and and then convert it to a one-dimensional array. But I still get the same error.</p>
  
  <pre><code>    List&lt;Color&gt; colorList = new ArrayList&lt;Color&gt;();
  
      for(int x = 0; x &lt; N; x++){
          for(int y = 0; y &lt; N; y++){
  
  
              colorList.add(grid[x][y]);
  
          }
      }
  
      Color[] SortColors = colorList.toArray(new Color[colorList.size()]);       
  
      for(int x = 0; x &lt; SortColors.length; x++){
  
          R1 = SortColors[x].getRed();
         System.out.print(" " + SortColors[x]);
         System.out.print(" " + R1);
  
      }
  </code></pre>
  
  <p>It prints the following:</p>
  
  <pre><code>java.awt.Color[r=98,g=85,b=217] 98 java.awt.Color[r=254,g=110,b=177] 254Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
      at DrawGrid.ColourSorting.sortColours(ColourSorting.java:43)
  </code></pre>