title: Getting a NullPointerException when trying to create ArrayList
body: <p>I'm working on an arraylist that will add random tiles to a bag for a scrabble game. My teacher has done a horrible job of explaining things so I'm having to work through this all. I've created constructors for the bag and am attempting to create the bag but am getting a null pointer exception when calling. </p>
  
  <p>Exception in thread "main" java.lang.NullPointerException
      at h2.RandBag.add(RandBag.java:11)</p>
  
  <p>Heres the code in main returning the error:</p>
  
  <pre><code>    for (Integer ival : rbag)
        System.out.println(ival);
  </code></pre>
  
  <p>And heres the methods I'm using for constructing. </p>
  
  <pre><code>private ArrayList&lt;E&gt; bag; // container
  private Random rand;      // random generator
  
  //constructors
  public RandomBag(){
    this.bag = new ArrayList&lt;E&gt;();
    this.rand = new Random();
  
  public RandomBag(int seed) {
    this.bag = new ArrayList&lt;E&gt;();
    this.rand = new Random(seed);
  </code></pre>
  
  <p>And the iterator since it returns null and that could be the problem.</p>
  
  <pre><code>public Iterator&lt;E&gt; iterator() {
  
      return null;
  }
  </code></pre>
  
  <p>I've tried returning different things but get an error each time. Iterators haven't been explained all that much so I might be missing something. </p>
  
  <pre><code>RandomBag&lt;Integer&gt; rbag = new RandomBag&lt;Integer&gt;(17);
  for (int i = 0; i &lt; 8; ++i)
  rbag.add(10+i);
  </code></pre>