Results 1 to 2 of 2
  1. #1
    m0v0n is offline Member
    Join Date
    Sep 2009
    Rep Power

    Default Exception when program is run.

    I get an IndexNotFoundException on line 77. The one that says "int currentScrambledWordLength = (eachScrambledWord.get(atScrambledWord)).length(); "
    How do I fix this?:confused:

    Java Code:
    /*-Author: Matthew Vaughan-*/
    import java.util.*;
    public class Unscramble {
    	public static void main(String args[]){
    Scanner myScanner = new Scanner(;
    		Scanner keyboard = new Scanner(; //input from the keyboard
    		String words; //the words that are to be unscrambled
    		ArrayList<String> eachScrambledWord = new ArrayList<String>(); //Will contain scrambled words
    		ArrayList<String> eachUnscrambledWord = new ArrayList<String>(); //Will contain unscrambled words read from text file
    		int howManyWords; //how many words the user wants unscrambled
    		System.out.println("How many words do you want unscrambled? ");
    		int spaces[] = new int[howManyWords-2];
    		System.out.print("Enter the words you want unscrambled separated by a space: ");
    		words = keyboard.nextLine(); //all the words the user wants unscrambled
    		for(int i = 0; i<howManyWords-2; i++){ //this for loop will find all the positions of the spaces so it can separate
    		//the string in to individual words and store them in the array list "eachScrambledWord"
    			spaces[i] = words.indexOf(" ");
    			spaces[i] = words.indexOf(" ", spaces[i-1] + 1);
    		for(int ii=0; ii < howManyWords-2; ii++){ //adds words to the array list
    			eachScrambledWord.add(words.substring(0, spaces[0]));
    			eachScrambledWord.add(words.substring(spaces[ii -1] + 1, spaces[ii]));
    String currentLine;
    			BufferedReader fromFile = new BufferedReader(new FileReader("wordlist.txt")); //object that reads the text file
    if (!fromFile.ready()){ //makes sure reader is ready
                    throw new IOException();
                while ((currentLine = fromFile.readLine()) != null){ //makes sure that the reader hasn't reached the end of the file
    			}catch(Exception eee){
    				System.out.println("IO Error\nFile may not exist in the directory of this program\nMake sure you enter the full path to the file");
    /*Hooray for 2D Arrays!*/
    int[][] wordsSameLength = new int[howManyWords][eachUnscrambledWord.size()];
    /*Hooray for nested for loops!*/
    				for(int atLine=0;atLine<eachUnscrambledWord.size();atLine++){
    					for(int atScrambledWord = 0;atScrambledWord<howManyWords; atScrambledWord++) {
    						int currentScrambledWordLength = (eachScrambledWord.get(atScrambledWord)).length();
    						int currentUnscrambledWordLength = (eachUnscrambledWord.get(atLine)).length();
    							wordsSameLength[atScrambledWord][atLine] = atLine;

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. Replies: 4
    Last Post: 10-25-2010, 08:42 PM
  2. SQL Exception from Java program
    By jyotigupta6 in forum New To Java
    Replies: 1
    Last Post: 10-28-2008, 07:27 PM
  3. SQL Exception from java program
    By jyotigupta6 in forum New To Java
    Replies: 3
    Last Post: 10-27-2008, 07:35 PM
  4. Replies: 3
    Last Post: 04-07-2008, 06:56 PM
  5. Replies: 1
    Last Post: 03-08-2008, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts