title: Java - Why am I getting this NullPointerException?
body: <p>I don't understand why this is giving me a null pointer exception when I try to add a value to the a1[i] array. </p>
  
  <pre><code>public class Array {
  
  String text;
  int total = 0, count = 0;
  
  Array[] a1 = new Array[100];
  Scanner scan = new Scanner(System.in);
  
  
  
  public void setData() {
      int i=0;
  
      System.out.println(a1.length);
      do {
  
          System.out.println("Enter some data: ");
          text = scan.next();
          if (text.equals("end"))break;
          a1[i].text = text; //I get a null pointer exception here. Not sure why. 
          i++;
  
      } while (true);
  
      }
  </code></pre>