# Processing Array size

**URL:** https://discourse.processing.org/t/processing-array-size/21569
**Category:** Beginners
**Created:** [June 4, 2020, 8:03pm UTC](https://discourse.processing.org/t/processing-array-size/21569 "2020-06-04T20:03:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)
#### Post date: [June 4, 2020, 8:03pm UTC](https://discourse.processing.org/t/processing-array-size/21569/1 "2020-06-04T20:03:22Z")

</div>

I have a Processing sketch that reads folders of images and displays them.

It has been working great but it seems that as soon as the folder got over 500 images I get an error.

My code is pretty straight forward.

I define a Pimage array at the start of my sketch

PImage gridImage[];

Then populate the array with the images from the folder.

gridImage[i] = loadImage(f.getName() );

It works great until I seem to max out the array as I get and “array out of bounds error” if there are more than 500 images in the folder.

Any ideas?

---

<div class="post-metadata">

### Author: ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)
#### Post date: [June 4, 2020, 9:20pm UTC](https://discourse.processing.org/t/processing-array-size/21569/2 "2020-06-04T21:20:24Z")

</div>

You need to set you array length to the number of images in the folder …

if you don’t know that number then you can use an ArrayList.

[https://processing.org/reference/Array.html](https://processing.org/reference/Array.html)  
[https://processing.org/reference/ArrayList.html](https://processing.org/reference/ArrayList.html)

---

<div class="post-metadata">

### Author: ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)
#### Post date: [June 4, 2020, 10:08pm UTC](https://discourse.processing.org/t/processing-array-size/21569/3 "2020-06-04T22:08:32Z")

</div>

Cool, I’ll try that.

Seems odd that it would work for 499 images then fail.

Thanks

---

<div class="post-metadata">

### Author: ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)
#### Post date: [June 4, 2020, 10:26pm UTC](https://discourse.processing.org/t/processing-array-size/21569/4 "2020-06-04T22:26:46Z")

</div>

yeah … i’m not sure how you get 499 without allocating memory.

---

<div class="post-metadata">

### Author: ![philspitler](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@philspitler](https://discourse.processing.org/u/philspitler)
#### Post date: [June 5, 2020, 12:01am UTC](https://discourse.processing.org/t/processing-array-size/21569/6 "2020-06-05T00:01:43Z")

</div>

Ok… sorted… I had defined the array length further down the sketch when I first started… thinking there was no way I would have more than 500 images…

Thanks for all the suggestions
