# "String Index Out Of Bounds Exception: String index out of range: -1907998" Unknow error

**URL:** <https://discourse.processing.org/t/string-index-out-of-bounds-exception-string-index-out-of-range-1907998-unknow-error/37372>\
**Category:** Libraries\
**Created:** [June 6, 2022, 5:57pm UTC](https://discourse.processing.org/t/string-index-out-of-bounds-exception-string-index-out-of-range-1907998-unknow-error/37372 "2022-06-06T17:57:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DybaTube](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@DybaTube](https://discourse.processing.org/u/DybaTube)\
**Post date:** [June 6, 2022, 5:57pm UTC](https://discourse.processing.org/t/string-index-out-of-bounds-exception-string-index-out-of-range-1907998-unknow-error/37372/1 "2022-06-06T17:57:44Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

I am trying to import my p5js code to processing, its almost working, but when i try to load the program it cames this error:  
StringIndexOutOfBoundsException: String index out of range: -1907998

The code if you want:

```auto
import processing.video.*;
String density = "BadAppleBadAppleBadAppleBadAppleBadAppleBadApple";

Movie badapple;

void setup() {
  size(128,72);
  badapple = new Movie(this,"BadApple.mp4");
  badapple.play();

}

void draw() {
  badapple.loadPixels();
  String asciiImage = "";
  for (int j = 0; j < badapple.height; j++) {
    for (int i = 0; i < badapple.width; i++) {
      int pixelIndex = (i + j * badapple.width) * 4;
      int r = badapple.pixels[pixelIndex + 0];
      int g = badapple.pixels[pixelIndex + 1];
      int b = badapple.pixels[pixelIndex + 2];
      int avg = (r + g + b) / 3;
      int len = density.length();
      int charIndex = floor(map(avg,0,255,0,29));
      int c = density.charAt(charIndex);
      if (c == ' ') asciiImage += "&nbsp;";
      else asciiImage += c;
    }
    asciiImage += "\n";
  }
  text(asciiImage,0,0);

}

void movieEvent(Movie m) {
  m.read();
}

```

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 6, 2022, 7:13pm UTC](https://discourse.processing.org/t/string-index-out-of-bounds-exception-string-index-out-of-range-1907998-unknow-error/37372/2 "2022-06-06T19:13:58Z")

</div>

Hi @DybaTube,

> [@DybaTube](#):
>
> I am trying to import my p5js code to processing, **its almost working**

Are you sure ?

Guess you should at least read first about…

[Images and Pixels tutorial](https://processing.org/tutorials/pixels)  
and  
[Reference pixels](https://processing.org/reference/pixels.html)

and for an example implementation maybe here  
[Ascii Video](https://github.com/processing/processing-video/blob/master/examples/Capture/AsciiVideo/AsciiVideo.pde)

Cheers  
— mnse
