arrayListOutOfBoundsException... Please Help?

Posted by Jacob on Stack Overflow See other posts from Stack Overflow or by Jacob
Published on 2010-06-13T06:04:16Z Indexed on 2010/06/13 6:12 UTC
Read the original article Hit count: 223

Filed under:

This is my class Debugger. Can anyone try and run it and see whens wrong? Ive spent hours on it already. :(

public class Debugger {

private String codeToDebug = "";

public Debugger(String code) {
    codeToDebug = code;
}

/**
 * This method itterates over a css file and adds all the properties to an arraylist
 */
public void searchDuplicates() {
    boolean isInside = false;
    ArrayList<String> methodStorage = new ArrayList();
    int stored = 0;
    String[] codeArray = codeToDebug.split("");

    try {
        int i = 0;
        while(i<codeArray.length) {
            if(codeArray[i].equals("}")) {
                isInside = false;
            }
            if(isInside && !codeArray[i].equals(" ")) {
                boolean methodFound = false;
                String method = "";
                int c = i;
                while(!methodFound) {
                    method += codeArray[c];
                    if(codeArray[c+1].equals(":")) {
                        methodFound = true;
                    } else {
                        c++;
                    }
                }
                methodStorage.add(stored, method);

                System.out.println(methodStorage.get(stored));
                stored++;

                boolean stillInside = true;
                int skip = i;
                while(stillInside) {
                    if(codeArray[skip].equals(";")) {
                        stillInside = false;
                    } else {
                        skip++;
                    }
                }
                i = skip;
            }
            if(codeArray[i].equals("{")) {
                isInside = true;
            }
            i++;
        }
    } catch(ArrayIndexOutOfBoundsException ar) {
        System.out.println("------- array out of bounds exception -------");
    }
}

/**
 * Takes in String and outputs the number of characters it contains
 * @param input
 * @return Number of characters
 */
public static int countString(String input) {
    String[] words = input.split("");
    int counter = -1;
    for(int i = 0; i<words.length; i++){
        counter++;
    }
    return counter;
}

public static void main(String[] args) {
    Debugger h = new Debugger("body {margin:;\n}");
    h.searchDuplicates();
}

}

© Stack Overflow or respective owner

Related posts about java