I'm trying to match at least 3 objects to each other in the most efficient way. I keep getting a null pointer error. I've tried a few different approaches and can't seem to figure it out. Any help would be much appreciated.
protected void boardFill(ArrayList<ArrayList<T>> twoDList) {
    for (int x = 0; x < COL; x++) {
        twoDList.add(new ArrayList<T>());
        for(int y = 0; y < ROW; y++) {
            twoDList.get(x).add(gems.newGem());             
        }          
    }
    for (int i = 0; i < COL; i++) {
        for (int j = 0; j < ROW; j++) {
            getObject(i, j, twoDList.get(i).get(j));
        }
    }
}
/*
 * move pieces down after being removed
 */
public void drop() {
}
/*
 * check if position is legal to move/swap
 */
public boolean legal(int row, int col) {      
    return false;
}
/*
 * check if pieces are matching
 */
public boolean matching(int r, int c) {
    boolean flag = false;
    return flag;
}
public void getObject(int i, int j, T type) {
   if (twoDList.get(i).get(j) == type) {
       coordinates.add(twoDList.get(i).get(j));
       if (i-1 >= 0) getObject(i - 1, j, type);
       if (i+1 < ROW) getObject(i + 1, j, type);
       if (j-1 >= 0) getObject(i, j - 1, type);
       if (j+1 < COL) getObject(i, j + 1, type);
   }
}
 
    