It would be a bit more helpful if you posted where the ArrayOutOfBoundsException was occurring.
It could be down to a number of reasons.

The initial indices could be out of bounds as your...