title: Java NullPointerException when adding to ArrayList?
body: <p>My code is throwing a NullPointerException, even though the object seems to properly exist.</p>
  
  <pre><code>public class IrregularPolygon {
  
      private ArrayList&lt;Point2D.Double&gt; myPolygon;
  
      public void add(Point2D.Double aPoint) {
          System.out.println(aPoint); // Outputs Point2D.Double[20.0, 10.0]
          myPolygon.add(aPoint); // NullPointerException gets thrown here
      }
  }
  
  // Everything below this line is called by main()
  
      IrregularPolygon poly = new IrregularPolygon();
      Point2D.Double a = new Point2D.Double(20,10);
      poly.add(a);
  </code></pre>
  
  <p>Why is this happening?</p>