Why is there a null exception pointer error being thrown and how can i fix this thank you. If you could explain what to do. I am trying to store each line from a txt file into an arraylist which goes into a larger array list of seperate lines.
    public static ArrayList<ArrayList<String>> addAfter(String file1)throws IOException{
    Scanner scanner = new Scanner(new File(file1));
    ArrayList<ArrayList<String>> arr = new ArrayList<ArrayList<String>>(); 
    ArrayList<String> a = null;
    boolean check = false;
    while(scanner.hasNextLine())
    {
        String str = scanner.nextLine();
        String[] stringArr = str.split(" +");
        for(int i=0; i<stringArr.length; i++){
            a.add(stringArr[i]); //null exception being thrown here
        }
        stringArr = null;
        arr.add(a);
        a.clear();
    }
    return arr;
    }
 
     
     
     
    