Why does my program return the error "ArrayIndex Out Of Bounds Exception: 4"?

    genpart= split(genome[i], '1');

here you redefine genpart

Hence it has not 204 slots as you might expect but as many as split() returns, presumably 3.

Solution

so replace print(genpart[i] + " "); with println(genpart + " "); or even use printArray but without the [i]

OR say

// using i2 here within the for loop with i
for (int i2=0; i2<genpart.length;  i2++) {
  print(genpart[i2] + " "); 
}
1 Like