So I keep getting the NPException when running my spell checker. The exception occurs in my "edits" method. So here is the code of the method:
public ArrayList<String> edits (String word){
ArrayList<String> result = new ArrayList<String>();
result.add(word.substring(1));
result.add(word.substring(0, word.length()-1));
for (char c = 'a'; c <= 'z'; c++){
result.add(String.valueOf(c) + word);
}
for (char c = 'a'; c <= 'z'; c++){
result.add(word + String.valueOf(c));
}
for (int i = 0; i < word.length()-1; i++){
char[] c = word.toCharArray();
char temp = c[i];
c[i] = c[i+1];
c[i+1] = temp;
String swappedword = new String(c);
result.add(swappedword);
}
return result;
}
The error occurs at the 4th line, "result.add(word.substring(1));". I have looked at the related answers, but it didn't help me solve the problem. Help please! Thank you all!