这是一种从 java 中的稀疏矩阵中获取元素的方法。我不断收到java.lang.NullPointerException
错误消息。我查看了代码,找不到错误。
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