Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:41+00:00 2026-06-18T09:59:41+00:00

I’m writing some code for an interactive graphic I’m making which has three states.

  • 0

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: ArrayIndexOutOfBoundsException 8

I can’t seem to get rid of it even though I have the correct number of images loaded into my sketch.

Below is my code and I am working on a Macbook Pro OSX using Processing 2.0b7

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 < teams.length; i++) {
      teams[i] = loadImage(i + ".png");
    }

  teams2 = new PImage[m];
    for (int i = 0; i < teams2.length; i++) {
      teams2[i] = loadImage(i + ".gif");
    }

   quarterFinalWinners = new PImage[o];
    for (int o = 0; o < quarterFinalWinners.length; o++); {
   quarterFinalWinners[o] = loadImage(o + "_.png");
   }
}

/**----------------------------------------------------------------------------------------------------------------------------**/

void draw() {
  background(#000000);
  if ((x < width) && (y < height)) {
for (int i = 0; i < 16; i++);
    }


  }

/**----------------------------------------------------------------------------------------------------------------------------**/

public void keyPressed() {
  noLoop();

  switch(afconState) {
  case 1:
   afconState = 1;
   background(#000000);
  for (int i = 0; i < 16; i++) {
  image(teams[i], 150, 60*i);
  }
  }

  if ((key == 's') || (key == 'S')) {

    afconState = 2;
    background(#000000);
  for (int i = 0; i < 16; i++) {
  image(teams2[i], 150, 60*i);
  }
  }

  else if ((key == 'q') || (key == 'Q')) {
    afconState = 3;
    background(#000000);
  for (int i = 0; i < 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 < 16; i++) {
  image(teams2[i], 150, 60*i);
  }
  }

  else if ((key == 'q') || (key == 'Q')) {
    afconState = 3;
  for (int i = 0; i < 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 < 16; i++) {
  image(quarterFinalWinners[i], 150, 60*i);
  }
  }

  else if((key == 's') || (key == 'S')) {

    afconState = 2;
  background(#000000);
  for (int i = 0; i < 16; i++) {
  image(teams2[i], 150, 60*i);
  }
  }

  break;

  default:
  afconState = 1;
   background(#000000);
  for (int i = 0; i < 16; i++) {
  image(teams[i], 150, 60*i);
  }  

  if ((key == 's') || (key == 'S')) {
    afconState = 2;
  // modify the positions list
  for (int i = 0; i < 16; i++) {
  image(teams2[i], 150, 60*i);
  }
  }

  else if ((key == 'q') || (key == 'Q')) {
    afconState = 3;
  for (int i = 0; i < 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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:59:42+00:00Added an answer on June 18, 2026 at 9:59 am

    Most languages index from 0 (ie. 8 items will be indexed 0 through 7) – It looks like you are trying to reference an array item with index 8 which probably doesn’t exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.