Please, share the entire code.
You're probably indexing out of array. Your loop should look like
for (int i = 0; i < 5; i++)
i.e., stop before reaching index 5. You have 5 elements: 0, 1, 2, 3, 4; there's no element indexed with 5 (as it would be the 6th element).