Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing ArrayIndexOutOfBoundsException
    primarykey
    data
    text
    <p>I'm writing some code for an interactive graphic I'm making which has three states. I used a switch statement to move between the states which showcase an array of images. I uploaded all the images and yet when I call the one state which has an array of 8 images that I uploaded get an error message: <code>ArrayIndexOutOfBoundsException 8</code> </p> <p>I can't seem to get rid of it even though I have the correct number of images loaded into my sketch.</p> <p>Below is my code and I am working on a Macbook Pro OSX using Processing 2.0b7</p> <pre><code>PImage[] teams; int n = 24; PImage[] teams2; int m = 16; PImage [] quarterFinalWinners; int o = 7; PImage bg; float damping = 0.1; PFont font; String[] positions, prevPositions; float x; float y; int afconState = 3; /**----------------------------------------------------------------------------------------------------------------------------**/ public void setup() { size(600, 1600); bg = loadImage("football-pitch-hi.png"); positions = new String[]{"18", "26", "32", "45", "58", "56", "59", "61", "66", "69", "71", "85", "98", "100", "116", "133"}; prevPositions = new String[]{"14", "19", "25", "30", "34", "45", "52", "69", "71", "72", "87", "84", "89", "105", "107", "110"}; int a = 16; font = loadFont("Calibri-Bold-48.vlw"); textFont(font); frame.setResizable(true); teams = new PImage[n]; for (int i = 0; i &lt; teams.length; i++) { teams[i] = loadImage(i + ".png"); } teams2 = new PImage[m]; for (int i = 0; i &lt; teams2.length; i++) { teams2[i] = loadImage(i + ".gif"); } quarterFinalWinners = new PImage[o]; for (int o = 0; o &lt; quarterFinalWinners.length; o++); { quarterFinalWinners[o] = loadImage(o + "_.png"); } } /**----------------------------------------------------------------------------------------------------------------------------**/ void draw() { background(#000000); if ((x &lt; width) &amp;&amp; (y &lt; height)) { for (int i = 0; i &lt; 16; i++); } } /**----------------------------------------------------------------------------------------------------------------------------**/ public void keyPressed() { noLoop(); switch(afconState) { case 1: afconState = 1; background(#000000); for (int i = 0; i &lt; 16; i++) { image(teams[i], 150, 60*i); } } if ((key == 's') || (key == 'S')) { afconState = 2; background(#000000); for (int i = 0; i &lt; 16; i++) { image(teams2[i], 150, 60*i); } } else if ((key == 'q') || (key == 'Q')) { afconState = 3; background(#000000); for (int i = 0; i &lt; 16; i++) { image(quarterFinalWinners[i], 150, 60*i); } } break; /**----------------------------------------------------------------------------------------------------------------------------**/ case 2: if((key == 's') || (key == 'S')) { afconState = 2; background(#000000); for (int i = 0; i &lt; 16; i++) { image(teams2[i], 150, 60*i); } } else if ((key == 'q') || (key == 'Q')) { afconState = 3; for (int i = 0; i &lt; 16; i++) { image(quarterFinalWinners[i], 150, 60*i); } } break; case 3: background(#000000); if ((key == 'q') || (key == 'Q')) { afconState = 3; for (int i = 0; i &lt; 16; i++) { image(quarterFinalWinners[i], 150, 60*i); } } else if((key == 's') || (key == 'S')) { afconState = 2; background(#000000); for (int i = 0; i &lt; 16; i++) { image(teams2[i], 150, 60*i); } } break; default: afconState = 1; background(#000000); for (int i = 0; i &lt; 16; i++) { image(teams[i], 150, 60*i); } if ((key == 's') || (key == 'S')) { afconState = 2; // modify the positions list for (int i = 0; i &lt; 16; i++) { image(teams2[i], 150, 60*i); } } else if ((key == 'q') || (key == 'Q')) { afconState = 3; for (int i = 0; i &lt; 16; i++) { image(quarterFinalWinners[i], 150, 60*i); } } } redraw(); } void mousePressed () { // revert to previous array. We can only do this once. // if someone pressed the key seven times, we can't revert // seven times, because the code only has one history state // that is updated every time a key is pressed // redraw now that our state has changed redraw(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload