title: Accessing a pojo object using arraylist
body: <p>i am trying to solve the following project where I need to choose out the best customer's based on their purchases. All the necessary details like name,and amount purchased is included in my POJO object(Customer).
  I made an ArrayList of Cusomers and trying to access getName()/getAmount method in a for Loop.</p>
  
  <pre><code>              import java.util.ArrayList;
                 import java.util.Scanner;
  
      public class Store {
       ArrayList&lt;Customer&gt; Customers = new ArrayList&lt;&gt;();
      Customer[] csa = new Customer[1000];
  
       public void addSale(String customerName, double amount) {
      String cn = customerName;
      double am = amount;
      Customer cs = new Customer(cn, am);
      Customers.add(cs);
  }
  
  public String nameOfBestCustomer() {
      String name = null;
      //Customer csa=new Customer();
      double largest = csa[0].getAmount();
  
      // gives me:java.lang.NullPointerException
  
      for (int i = 1; i &lt; Customers.size(); i++) {
  
          if (largest &lt; csa[i].getAmount()) {
              largest = csa[i].getAmount();
              name = csa[i].getName();
          }
      }
  
      // return name+""+largest;
      return name;
  }
  
  
  public static void main(String[] args) {
  
      Store s = new Store();
      double am;
  
      Scanner scanner = new Scanner(System.in);
  
      while (true) {
  
          System.out.println("Enter Customer name:");
          String cn = scanner.next();
  
          if (cn.equals("done")) {
              am = 0;
              scanner.close();
  
              break;
          } else {
              System.out.println("Enter Amount:");
              am = scanner.nextDouble();
              s.addSale(cn, am);
  
          }
      }
  
      System.out.println("Best customer " + s.nameOfBestCustomer());
  
  }
  
              }
  </code></pre>
  
  <p>Is it okay to use  Customer[] csa = new Customer[1000]? when I already have an Arraylist for Customers?</p>
  
  <p>Can anybody tell me how to access customer-methods using Array or ArrayList? And also why is largest = csa[0].getAmount() giving me a NullPointerException?</p>