This is a method that gets a element from a Sparse Matrix in java. I keep getting a java.lang.NullPointerException
error. I have looked over the code and can't find the error.
public int getElement(int row,int col){
int result = 0;
MatrixEntry matrixentry = null;
if ((row >= 0) && (row < getNumRows()) &&
(col >= 0) && (col < getNumCols())) {
if (col == colArray[col].getColumn() && row ==rowArray[row].getRow()){
matrixentry = rowArray[row];
while (matrixentry.getColumn() < col) {
matrixentry = matrixentry.getNextColumn();
} // end while
if (matrixentry.getColumn() > col){
return 0;
}
if (matrixentry == null){
return 0;
}//
result = matrixentry.getData();
}//
}//
return result;
} // end