I need to write a method that rotates a matrix (of objects) by 90 degrees, both directions.

for example - 

```
( 0,0,0) (0,0,0) (0,0,0) (0,0,0)

( 1,1,1) (1,1,1) (1,1,1) (1,1,1)

( 2,2,2) (2,2,2) (2,2,2) (2,2,2)

```

becomes - 

```
(2,2,2) (1,1,1) (0,0,0)

(2,2,2) (1,1,1) (0,0,0)

(2,2,2) (1,1,1) (0,0,0)

(2,2,2) (1,1,1) (0,0,0) 

```

I can't get over the "ArrayIndexOutOfBoundsException" error.

This is my work so far -

```
private RGBColor [][] _picture;
private int _row;
private int _col;

public RGBImage(RGBColor[][] pixels)
{
    _picture = new RGBColor [pixels.length][pixels[0].length];
    _row = pixels.length;
    _col = pixels[0].length;

    for(int i = 0 ; i < pixels.length ; i++)
    {
        for(int j = 0 ; j < pixels[0].length ; j++)
        {
            _picture[i][j] = pixels[i][j];
        }
    }
}

public double[][] toGrayscaleArray ( )
{
    double [][] copyToGrayscale = new double [_row][_col];
    for(int i = 0 ; i < _row ; i++)
        {
            for(int j = 0 ; j < _col ; j++)
            {
               copyToGrayscale [i][j] = _picture[i][j].convertToGrayscale();
            }
        }
        return copyToGrayscale;
}

public void rotateCounterClockwise ( )
{
    RGBImage copy = new RGBImage(_col,_row);
    for(int i=0 ; i < _col ; i++)
    {
        for(int j=_row-1 ; j >0 ; j--)
        {
            copy._picture[i][j]=_picture[j][i];
        }
    } 
    _picture = copy.toRGBColorArray();     
}

```

What should i do?
thanks.