I'm making a program that will count how many different combinations you can get of a string. The counting works fine, but when I tried to make a function that creates a list of words with combinations, I get java.lang.ArrayIndexOutOfBoundsException.
The function is attached below and is used this way:
Code:
int c = calculateCombinations(t.getText());
String[] arr = new String[c];
getWordList(createWordList(arr, "", t.getText()))
I've tried to put other numbers than c, but it doesn't matter. The function should work but I think there is a stack problem in the createWordList().
Can somebody help me with this?
Ever heard of debugging? You can actually see where it goes wrong...
Anyway, the reason why you have this OutOfBoundException is because you are trying to set a element of the array at index = length.
Index is 0-based, length = 1 based (number of elements in the array).
Eg.:
Given: An array "test" with 4 element
the result of test.length is "4". The index of 4th element is '3'. That's why you get this exception.
*Edit* this happens in your text-file at line 33...
Bookmarks