Step back from the program a minute and think
about what you are trying to do.
If the number of columns is not equal to the number of rows, you must create a new array.
For example, suppose the original has 600 rows and 800 columns, Then the rotated image will have 800 rows and 600 columns. You can not simply exchange values the elements of the rows and columns of the original array. Period.
Now go back to your program and see why it absolutely must create an array out-of-bounds exception for a non-square image. Every single time.
Create a new array such that the height of the new array is equal to the width of the original and the width of the new array is equal to the height of the original.