If an array in
Java has N elements, the index of the first element is 0, and the index of the last element is N-1. You seem to be starting at 1 and going up to, well, various numbers. But I see several loops that go to N, and some others that might go higher, but I can't tell. Anyway, trying to access element N will cause an ArrayIndexOutOfBounds, because there is no element N.
Also, it would be helpful if you look carefully at the stack trace - in particular, at the topmost line of the stack trace. There's a line number there, which is very useful in determining which line caused the exception. If my hints above don't solve your problem, please tell us exactly which line threw the exception. For that matter, the exact full text of the exception may also be helpful as well. But remember that we can't look at a line number and tell which line it is, because we don't have the complete file. You need to look at the exception and figure out what it means.