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

please format code with </> button * homework policy * asking questions

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:

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();
}

Hi @DybaTube,

Are you sure ?

Guess you should at least read first about…

Images and Pixels tutorial
and
Reference pixels

and for an example implementation maybe here
Ascii Video

Cheers
— mnse