I want to create a matrix with LinkedLists anf fill all the cells with 0.
private LinkedList<LinkedList<T>> matrix;
private int rows;
private int columns;
// constructor
public Matrix(int rows, int columns){
this.rows = rows;
this.columns = columns;
for(int i=0; i<rows; i++){
for(int j=0; j<columns; j++){
matrix.get(i).add(0); // here I get the NullPointerException
}
}
}
What am I doing wrong?