# Line Graph - ArrayIndexOutOfBoundsException: 570

**URL:** <https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085>\
**Category:** Coding Questions\
**Created:** [January 15, 2021, 11:59am UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085 "2021-01-15T11:59:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JennyMcCreadie](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@JennyMcCreadie](https://discourse.processing.org/u/JennyMcCreadie)\
**Post date:** [January 15, 2021, 11:59am UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085/1 "2021-01-15T11:59:41Z")

</div>

Hello, I’m following a tutorial on making a dynamic linegraph whilst using my own data. I’ve come across an error which I’m unable to fix myself and would really appreciate some fresh eyes on this 🙂

I know I’m doing something wrong with my array values, but I can’t work out where I’m going wrong.

Main Sketch:

```auto
String filename = "Simplified 2019 + 2020 Steps Data.csv";
String[] rawData;

void setup(){
processData();
  
}

void draw() {
  
  
  
}

void processData(){
    rawData = loadStrings(filename);
  for(int i = 1; i < rawData.length; i+=9) {
    Year y = new Year();
    for (int j = 1; j < 9; j++) {
   String[] thisRow = split(rawData[i+j], ",");
   println(thisRow[1]);
    
  }
 }
}
  

```

Tab 2 (“Year”)

```auto
class Year {
  
  // variables
  int level;
  int[] months = {1, 2, 3, 4, 5, 6, 7, 8, 9};
 int [] steps = new int[9];
  
  // constructor
  Year() {
 
  }
  // functions
  
}

```

And for good measure, here is a screenshot of some of my data (since I can’t upload the CSV file):

 ![Screenshot 2021-01-15 at 11.58.08](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/57b1512fa1f5fe868cb4e8c0be34f6afe13b3787.jpeg)

I know this is something very simple I’m overlooking, but I thank you heaps if you are able to help me on this! 🙂

---

<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:** [January 15, 2021, 12:06pm UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085/2 "2021-01-15T12:06:45Z")

</div>

> [@JennyMcCreadie](#):
>
> ```auto
> String[] thisRow = split(rawData[i+j], ",");
> println(thisRow[1]);
> 
> ```

this is causing your ArrayIndexOutOfBoundsException?

Surround the lines with if (i+j \< rawData.length) {…}

because of the i+=9 you will probably go over the end of the array

---

<div class="post-metadata">

**Author:** ![JennyMcCreadie](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@JennyMcCreadie](https://discourse.processing.org/u/JennyMcCreadie)\
**Post date:** [January 15, 2021, 12:15pm UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085/4 "2021-01-15T12:15:02Z")

</div>

Thanks so much for getting back to me! Sorry for being dumb, but could you please show me an example? Is it like this:

if(int i = 1; i \< rawData.length; i+=9) {  
Year y = new Year();  
for (int j = 1; j \< 9; j++) {  
String[] thisRow = split(rawData[i+j], “,”);  
println(thisRow[1]);

}  
}

I tried it this way, but it is saying I’ve got an unexpected token, I think I’ve done it wrong haha

Do you know if I could change my array number to fix it at all? My months go up to 9, so I’ve tried making the value “8” since I know an array counts from 0, but that didn’t work either

---

<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:** [January 15, 2021, 12:17pm UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085/5 "2021-01-15T12:17:42Z")

</div>

```auto

void processData() {
  rawData = loadStrings(filename);
  for (int i = 1; i < rawData.length; i+=9) {
    Year y = new Year();
    for (int j = 1; j < 9; j++) {

      if (i+j < rawData.length) {// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        String[] thisRow = split(rawData[i+j], ",");
        println(thisRow[1]);
      } // new if/////////////////////////////
    }//for
  }//for
}//func

```

---

<div class="post-metadata">

**Author:** ![JennyMcCreadie](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@JennyMcCreadie](https://discourse.processing.org/u/JennyMcCreadie)\
**Post date:** [January 15, 2021, 12:20pm UTC](https://discourse.processing.org/t/line-graph-arrayindexoutofboundsexception-570/27085/6 "2021-01-15T12:20:17Z")

</div>

> [@Chrisir](#):
>
> ```auto
> for (int i = 1; i < rawData.length; i+=9) {
> Year y = new Year();
> for (int j = 1; j < 9; j++) {
> 
> if (i+j < rawData.length) {
> 
> ```

You are a genius, thank you so much! I really appreciate it 😄
