import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; public class Methods { String words[] = new String[10]; BufferedReader bufReader = null; HashSet wordList = null; public void getNumbers() throws IOException { try { bufReader = new BufferedReader (new FileReader("wordlist.txt")); } catch (Exception e) { System.out.println ("File not found.\n"); } String line = ""; while((line = bufReader.readLine()) != null) { wordList.add(line); } for(int i=0; i<10; i++) { if(i==0) words[i]=SavitchIn.readLine().substring(2); else words[i]=SavitchIn.readLine().substring(3); } } ArrayList permutationsOf(String s) { ArrayList result = new ArrayList(); if (s.length() == 1) { // base case // return a new ArrayList containing just s result.add(s); return result; } // continued... else { // separate the first character from the rest char first = s.charAt(0); String rest = s.substring(1); // get all permutationsOf the rest of the characters ArrayList simpler = permutationsOf(rest); // recursive step // for each permutation, for (String permutation : simpler) { // extra work // add the first character in all possible positions, and ArrayList additions = insertAtAllPositions(first, permutation); // put each result into a new ArrayList result.addAll(additions); } return result; } } //Given one String representing one permutation of n-1 characters, we want to return all permutations resulting from inserting a given character in all n possible positions private ArrayList insertAtAllPositions(char ch, String s) { ArrayList result = new ArrayList(); for (int i = 0; i <= s.length(); i++) { String inserted = s.substring(0, i) + ch + s.substring(i); result.add(inserted); } return result; } public void comparetoList() { for(int i=0; i<10; i++) { for(int z=0; z<(permutationsOf(words[i]).size()); z++) { if(wordList.contains((permutationsOf(words[i])).get(z))) { System.out.println((permutationsOf(words[i])).get(z)); } } } } } This gives an error: Exception in thread "main" java.lang.NullPointerException at Methods.getNumbers(Methods.java:23) at HashSolution.main(HashSolution.java:8) I'm not sure why this would happen, I put the wordlist.txt file in the project folder.