Reading object from a file and saving it into ArrayList
<p>I have a problem with reading specific object from a file and saving it into ArrayList.</p>

<p>First I write a single customer using <code>writeCustomer()</code>. Then I write all records from <code>List customerList</code> and save them to the file. This works great.</p>

<p>Then I want to read the saved file so I read one line using <code>readCustomer()</code>. This method returns one <code>Customer</code> and then I want to return a list with all <code>Clients</code> using <code>readData()</code> and read it,  I have nullPointerException in line list.add(readCustomer(bufferedReader));</p>

<p>My <code>Class Customer</code> has one constructor and is has an override method <code>toString()</code>.</p>

<pre><code>public class SaveCustomers {

public static void main(String[] args) throws IOException {

    List&lt;Customers&gt; customersList = new ArrayList&lt;&gt;();
    customersList.add(new Customers("ABC", 10));
    customersList.add(new Customers("SGS", 20));
    customersList.add(new Customers("FSD", 30));

    try (PrintWriter out = new PrintWriter("customer.txt", "UTF-8"))
    {         writeData(customersList, out);      }


    BufferedReader bufferedReader = new BufferedReader(new FileReader("customer.txt"));
    List&lt;Customers&gt; newList =  readData(bufferedReader);


    for(Customers c: newList){
        System.out.println(c);
    }
}

private static void writeCustomer(PrintWriter out, Customers customers){
    out.println(customers.getName()+"|"+customers.getTarrif());
}

private static void writeData(List&lt;Customers&gt; customersList, PrintWriter out){
    for(Customers c:customersList){
        writeCustomer(out, c);
    }
}

public static Customers readCustomer(BufferedReader bufferedReader) throws IOException {
    String line = bufferedReader.readLine();
    String [] tokens = line.split("\\|");
    String name = tokens[0];
    int time = Integer.valueOf(tokens[1]);
    return new Customers(name, time);
}

public static List&lt;Customers&gt; readData(BufferedReader bufferedReader) throws IOException {

    List&lt;Customers&gt; list = new ArrayList&lt;&gt;();
        while (bufferedReader.readLine() != null) {
            list.add(readCustomer(bufferedReader));
        }
    return list;
}}
</code></pre>