# ArrayIndexOutOfBoundsException: 168270

**URL:** <https://discourse.processing.org/t/arrayindexoutofboundsexception-168270/19057>\
**Category:** Beginners\
**Created:** [March 26, 2020, 9:20pm UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-168270/19057 "2020-03-26T21:20:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jojo1515](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jojo1515](https://discourse.processing.org/u/jojo1515)\
**Post date:** [March 26, 2020, 9:20pm UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-168270/19057/1 "2020-03-26T21:20:14Z")

</div>

Hey guys

I have been trying to manipulate pixels on an image, following the youtube tutorial: [https://www.youtube.com/watch?v=j-ZLDEnhT3Q](https://www.youtube.com/watch?v=j-ZLDEnhT3Q) by the Coding Train.

I can’t seem to get it to work. Error code reads… ArrayIndexOutOfBoundsException: 168270

Here is my code:

```auto
PImage sunf;

void setup(){
 size (474, 355); 
  sunf = loadImage("sunf.jpg");
}

void draw(){
  image(sunf, 0, 0);
  loadPixels();
  sunf.loadPixels();
  for(int x = 0; x < width; x++){
    for(int y = 0; y < width; y++){
      int loc = x+y*width;
      float r = red(sunf.pixels[loc]);
      float g = green(sunf.pixels[loc]);
      float b = blue(sunf.pixels[loc]);
      pixels[loc] = color(r,g,b*2); 
}
  }
  updatePixels();
}

```

Any help/advice would be greatly appreciated. Thanks.

J

---

<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:** [March 26, 2020, 9:27pm UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-168270/19057/2 "2020-03-26T21:27:27Z")

</div>

> [@jojo1515](#):
>
> for(int y = 0; y \< width; y++){

Try instead:

```auto
for(int y = 0; y < height; y++){

```

---

<div class="post-metadata">

**Author:** ![jojo1515](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@jojo1515](https://discourse.processing.org/u/jojo1515)\
**Post date:** [March 26, 2020, 10:07pm UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-168270/19057/3 "2020-03-26T22:07:06Z")

</div>

Duh! Thanks TfGuy44, appreciate your help, embarrassed about my incompetence
