# I am having an Issue

**URL:** https://discourse.processing.org/t/i-am-having-an-issue/2367
**Category:** Coding Questions
**Created:** [August 4, 2018, 5:28pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367 "2018-08-04T17:28:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![magic\_moose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magic_moose/32/1001_2.png) [@magic\_moose](https://discourse.processing.org/u/magic_moose)
#### Post date: [August 4, 2018, 5:28pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/1 "2018-08-04T17:28:25Z")

</div>

I am trying to make a bar graph for the following data however my “i” integer is not being recognized.

String[] name = {  
“1997:”,  
“1998:”,  
“1999:”,  
“2000:”,  
“2001:”,  
“2002:”,  
“2003:”,  
“2004:”,  
“2005:”,  
“2006:”,  
“2007:”,  
“2008:”,  
“2009:”,  
“2010:”,  
“2011:”,  
“2012:”,  
“2013:”,  
“2014:”,  
“2015:”,  
“2016:”,  
};

int[] fires = {

6,835 ,  
5,227 ,  
7,562 ,  
5,177 ,  
6,223 ,  
5,759 ,  
5,961 ,  
5,574 ,  
4,908 ,  
4,805 ,  
3,610 ,  
3,593 ,  
2,858 ,  
2,434 ,  
3,056 ,  
2,922 ,  
3,672 ,  
2,920 ,  
3,231 ,  
2,816 ,  
};

void setup(){  
size(500,500);  
}

void draw(){  
int x =0;  
for(int i=0; i\<10; i++){

```
if(mouseX>x && mouseX<=x+40){
  fill(255, 96, 79);
}else{
  fill(255, 36, 13);
}

```

}

float h = map(fires[i], 2300, 7600, 36, 340);

rect(x+4, height-h, 32, h);

x+=8;  
}

I am very new to processing and need some help.

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [August 4, 2018, 5:45pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/2 "2018-08-04T17:45:27Z")

</div>

The brace that ends the for loop seems to be in the wrong place. It should probably be after the x += 8 line?

---

<div class="post-metadata">

### Author: ![magic\_moose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magic_moose/32/1001_2.png) [@magic\_moose](https://discourse.processing.org/u/magic_moose)
#### Post date: [August 4, 2018, 5:48pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/3 "2018-08-04T17:48:24Z")

</div>

I changed that however when I run it now I get an error “ArrayIndexOutOfBoundsException: 40” with my float h line being highlighted

---

<div class="post-metadata">

### Author: ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)
#### Post date: [August 4, 2018, 6:44pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/4 "2018-08-04T18:44:05Z")

</div>

Hi magic\_moose,

You can use `name.length` and `fires.length` to find the number of entries you have in each of your arrays. This will help when using a for-loop to run through them. By my count, `name` has 20 entries while `fires` has 40. I’m assuming that there’s a connection between the two, like every 2 entries in `fires` is to be matched with every 1 entry in `name`?

```auto
void setup() {
  size(500, 500);
  println("name's length", name.length);
  println("fires's length", fires.length);

  int minsz = min(fires.length, name.length);
  int relsz = max(fires.length, name.length) / minsz;
  println(relsz);

  for (int i = 0, j = 0; i < minsz; ++i, j += relsz) {
    println(name[i], fires[j], ",", fires[j + 1]);
  }
}

```

You can work with more than one variable in your for-loop to keep your arrays in sync. In this case, my variable `i` is matched with the `name` array, while `j` is matched with the `fires` array. Because `fires` is twice as big, `j` must be incremented twice as fast as `i`. This is why I used `j += relsz` (relative size or length, 2) in the third section of the for-loop. `i` and `j` only exist within the for-loop, and disappear from memory after it finishes. `minsz` and `relsz` will disappear after `setup` finishes.

A sample of what this sketch will print in the console:

```auto
1997: 6 , 835
1998: 5 , 227
1999: 7 , 562
2000: 5 , 177

```

I recommend watching Dan Shiffman’s videos, particularly this one on variable scope. Depending on where a variable like `float h` is located relative to your curly braces, `{` and `}`, Processing may not know that it exists or what information it contains.

[![](https://img.youtube.com/vi/pC7RUmHL2KY/hqdefault.jpg "6.4: Variable Scope - Processing Tutorial") ](https://www.youtube.com/watch?v=pC7RUmHL2KY)

Hope that helps out!

---

<div class="post-metadata">

### Author: ![magic\_moose](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/magic_moose/32/1001_2.png) [@magic\_moose](https://discourse.processing.org/u/magic_moose)
#### Post date: [August 4, 2018, 7:08pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/5 "2018-08-04T19:08:28Z")

</div>

Thank you for the help however where it comes with 40 outputs it was meant to be 20. the commas in the numbers were just to show a number placement ex: 1,000 = 1000.

Sorry for the confusion, I am just very very lost

---

<div class="post-metadata">

### Author: ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)
#### Post date: [August 4, 2018, 7:32pm UTC](https://discourse.processing.org/t/i-am-having-an-issue/2367/6 "2018-08-04T19:32:54Z")

</div>

Hi magic\_moose,

It’s very helpful that you pointed that out. Those commas are confusing Processing, too, because it uses commas to separate entries in an array, not for grouping within a number. So, although this isn’t solving your big problem yet, you can now get rid of a small problem which is making the bigger one harder to solve.

```auto
int[] fires = {
  6835, 5227, 7562, 5177, 6223,
  5759, 5961, 5574, 4908, 4805, 
  3610, 3593, 2858, 2434, 3056, 
  2922, 3672, 2920, 3231, 2816
};

int sz = fires.length;
for(int i = 0; i < sz; ++i) {
  println(i + 1, nfc(fires[i]));
}

```

If in the future I ever want to display the values in `fires` with commas to make them easier to read I can use [nfc](https://processing.org/reference/nfc_.html). (How I treat my information when I’m working in code is a separate design issue from how I format and display it to other people.)

Figuring out how to draw rectangles on the screen with a for-loop might be another sub-problem which will get you closer to your big goal. Again, Shiffman’s [videos](https://www.youtube.com/watch?v=h4ApLHe8tbk) are helpful, in my opinion.

Best,
