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.
Exception in thread "main" java.lang.NullPointerException at h2.RandBag.add(RandBag.java:11)
Heres the code in main returning the error:
for (Integer ival : rbag)
System.out.println(ival);
And heres the methods I'm using for constructing.
private ArrayList<E> bag; // container
private Random rand; // random generator
//constructors
public RandomBag(){
this.bag = new ArrayList<E>();
this.rand = new Random();
public RandomBag(int seed) {
this.bag = new ArrayList<E>();
this.rand = new Random(seed);
And the iterator since it returns null and that could be the problem.
public Iterator<E> iterator() {
return null;
}
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.
RandomBag<Integer> rbag = new RandomBag<Integer>(17);
for (int i = 0; i < 8; ++i)
rbag.add(10+i);