# ArrayoutOfBoundsException

**URL:** https://discourse.processing.org/t/arrayoutofboundsexception/4182
**Category:** Coding Questions
**Created:** [October 6, 2018, 7:09am UTC](https://discourse.processing.org/t/arrayoutofboundsexception/4182 "2018-10-06T07:09:32Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [October 6, 2018, 7:27am UTC](https://discourse.processing.org/t/arrayoutofboundsexception/4182/3 "2018-10-06T07:27:38Z")

</div>

Hi FreshlyChicken,

I can see that you tried to format your post but you didn’t use it correctly. Read this thread for more info: [Guidelines—Tips on Asking Questions](https://discourse.processing.org/t/guidelines-tips-on-asking-questions/2147)

Now to get back to your question, I’m not sure you really know what it means because the fix is quite obvious when you figured out where it is coming from. You are getting this error because you try to access an element of an array that does not exist because the array is too short.

In this case the bug is on this line:

```auto
if (randomZahl[i] == a)

```

You are using it in the following for loop:

```auto
for (int i = 0; i <= 25; ++i) {
  if (randomZahl[i] == a) {
    fill(0);
  }
}

```

You are making i going from 0 to 25 so at some point i will be 25 and thus you will be trying to access the 25th element of the randomZah array. But if we look at how you defined your array, we can see that it has only 5 elements:

```auto
int[] randomZahl = {3, 6, 8, 9, 4};

```

so you can only access element from index 0 to 5.

To cancel your errror you then only need to change your for loop to not exceed the size of your array:

```auto
for (int i = 0; i < 5; ++i) {
  if (randomZahl[i] == a) {
    fill(0);
  }
}

```

or even more fancy:

```auto
for (int i = 0; i < randomZahl.length; ++i) {
  if (randomZahl[i] == a) {
    fill(0);
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/arrayoutofboundsexception/4182)._
