EMZETT.
Login

ArrayIndexOutOfBoundsException

In short: An array was addressed with an index outside its range.

In more detail: Valid indices are 0 to length−1.

In Depth

Possible causes

  • Loop runs to <= instead of <.
  • Empty array.
  • Wrong index calculation.

Solutions

  1. Check loop bounds.
  2. Test the length before access.
  3. Work with for-each (iterate).

See also: Iterate, Java