0

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);
   }
}
ManoDestra
  • 6,325
  • 6
  • 26
  • 50
  • Null pointers are best solved by stepping through the code yourself with a debugger. Please see the duplicate I linked. – tnw Apr 21 '16 at 17:55
  • yeah I've been trying to, I figured out the null pointer. But no when I try to add those matching object to a point I am getting more than what I should. Even though it'll find the exact number of matches. – Kevin Cox Apr 23 '16 at 15:49

0 Answers0