Hi all. I'm trying to get a sound to play but whenever it plays it comes up with "Exception in thread java.lang.ArrayIndexOutOfBoundsException" error. I cna't determine the reason why. This error occurs in the test spelling method.
Code:
//words for the spelling test private String [] word = {"A", "Add", "Able", "Cast", "Brother", "Family", "Mayor", "Firm", "Many", "Cat"}; //variables for amount correct private int correct = 10; public int questionnum = 0; public boolean nextQ = false; public static int test =0; private String question = ""; GreenfootSound Right = new GreenfootSound("Correct.mp3"); GreenfootSound Wrong = new GreenfootSound("Wrong.mp3"); /** * Constructor for objects of class QuizWorld. * */ public QuizWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); addObject(new Message("Press 1 to test Spelling\n Press 2 to test Math", 1), getWidth()/2, getHeight()/2); } public void act() { if (nextQ == true) { if (test == 1) { testSpelling(); QuizInput.Quiztype = 1; } if (test == 2) { testMath(); QuizInput.Quiztype = 2; } } } public void testMath() { } public void testSpelling() { if (questionnum < 10) { question = word[questionnum] ; GreenfootSound questionsound = new GreenfootSound(question +".mp3"); questionsound.play(); questionnum = questionnum + 1; nextQ = false; } }