# Problem with arraylist

**URL:** <https://discourse.processing.org/t/problem-with-arraylist/980>\
**Category:** Processing\
**Created:** [June 15, 2018, 8:15am UTC](https://discourse.processing.org/t/problem-with-arraylist/980 "2018-06-15T08:15:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElectroSquid](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@ElectroSquid](https://discourse.processing.org/u/ElectroSquid)\
**Post date:** [June 15, 2018, 8:15am UTC](https://discourse.processing.org/t/problem-with-arraylist/980/1 "2018-06-15T08:15:43Z")

</div>

so, i have been attempting to create a neural network in processing, but after i get the error: ArrayIndexOutOfBoundException: Index 0, Size:0, i can not think of any way that this is caused

```auto
ArrayList<Float>generateNodes(int layer,int nodes) {
  // generates IndexOutOfBounds ArrayList[] layers=new ArrayList[layer+1];
  // same error as line 70 ArrayList[] layers={new ArrayList<ArrayList<Float>>(),new ArrayList<ArrayList<Float>>(),new ArrayList<ArrayList<Float>>()};
  ArrayList<ArrayList<Float>> layers=new ArrayList<ArrayList<Float>>();
  ArrayList<ArrayList<Float>> InternalNodes=new ArrayList<ArrayList<Float>>();
    if(layer==1) {
      for(int l=0; l<=inputs.length-1; l++) {
       layers.add(new ArrayList<Float>(Arrays.asList(node(inputs[l],weights.get(l)))));  
      }
    }
    else {
      for(int n=0; n<=nodes; n++) {
    layers.add(new ArrayList<Float>(Arrays.asList(node(InternalNodes.get(layer-1).get(n),weights.get(weights.size()-1)))));
      }
    }
   return layers.get(layers.size()-1);
  }
}

```

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [June 15, 2018, 8:42am UTC](https://discourse.processing.org/t/problem-with-arraylist/980/2 "2018-06-15T08:42:26Z")

</div>

If the size were 1, there would be one object in the ArrayList, and that one item would be at index 0.

But the size is 0, not 1. So there isn’t even one item in the ArrayList. So there’s nothing at index 0. Because if there was something at index 0, the size would be 1, not 0.

Which line are you getting the error on? Chances are good that you are trying to access - possibly return - the 0th item in an empty ArrayList. I mean, look at the return statement… Are you checking that `layers` has an item in it before you try to get the last one?

---

<div class="post-metadata">

**Author:** ![ElectroSquid](https://avatars.discourse-cdn.com/v4/letter/e/a88e57/32.png) [@ElectroSquid](https://discourse.processing.org/u/ElectroSquid)\
**Post date:** [June 15, 2018, 9:09am UTC](https://discourse.processing.org/t/problem-with-arraylist/980/3 "2018-06-15T09:09:55Z")

</div>

you where correct, thank you , yes, the problem was that the line that was supposed to initialize the arraylist only triggered when a boolean was set to true, and this boolean was false by default, thankyou
