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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | //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 ; } } |