This line:
for(i=0; i <= theCode.length();i++){
Should have a <
and not <=
. This is because you are executing the for
loop for the length of that string and one more. Since a String
is a zero based array, you try to find the character when i
= the length, and you can't, because there is no character there. It throws an exception because of this, since it can't find that character. So to fix this, use this code:
for(i=0; i < theCode.length();i++){