# ArrayList with boolean type crashing on use of the .get function

**URL:** <https://discourse.processing.org/t/arraylist-with-boolean-type-crashing-on-use-of-the-get-function/21807>\
**Category:** Coding Questions\
**Created:** [June 12, 2020, 1:22pm UTC](https://discourse.processing.org/t/arraylist-with-boolean-type-crashing-on-use-of-the-get-function/21807 "2020-06-12T13:22:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)\
**Post date:** [June 12, 2020, 1:22pm UTC](https://discourse.processing.org/t/arraylist-with-boolean-type-crashing-on-use-of-the-get-function/21807/1 "2020-06-12T13:22:27Z")

</div>

I am trying to use an arraylist of booleans but when using the .get function on the array the program crashes, so I figured I should have iniatilized the values however when trying to do so it simply seems to skip over the loop and says the variable in the loop is not used. I’m trying to get something like below to work. I’m getting an indexOutOfBoundsExeption with the error saying the size is 0  
ArrayList switches = new ArrayList(32);

void setup() {

size(200, 200);

for (int i = switches.size() - 1; i \>= 0; i–) {

```
boolean s = switches.get(i);

s = false;

```

}

if (switches.get(12)) {

```
ellipse(width/2, height/2, 50, 50);

```

}  
}

void mousePressed() {

switches.set(12, true);  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 12, 2020, 1:44pm UTC](https://discourse.processing.org/t/arraylist-with-boolean-type-crashing-on-use-of-the-get-function/21807/2 "2020-06-12T13:44:26Z")

</div>

```auto
ArrayList switches = new ArrayList(); //!!!!!!!

void setup() {
  size(200, 200);

  println(switches.size()); //!!!!!!!!!!!!!!

  for (int i =32; i >= 0; i--) {
    switches.add ( false ) ; //!!!!!!!!!!!
  }
}

/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
void draw() { /// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  if ( (boolean)switches.get(12)) { //!!!!!!!!
    ellipse(width/2, height/2, 50, 50);
  }
}

void mousePressed() {
  switches.set(12, true);
}

```

---

<div class="post-metadata">

**Author:** ![TheEternalDragon](https://avatars.discourse-cdn.com/v4/letter/t/8baadc/32.png) [@TheEternalDragon](https://discourse.processing.org/u/TheEternalDragon)\
**Post date:** [June 12, 2020, 3:18pm UTC](https://discourse.processing.org/t/arraylist-with-boolean-type-crashing-on-use-of-the-get-function/21807/3 "2020-06-12T15:18:24Z")

</div>

Ah thanks for helping me out with the syntax, couldn’t find a lot of info on that
