Check the value of i with the debugger. The Row value is dynamic but the declaration of the SmArray is hardcoded 20.
SmArray =new MatrixTerm [20];
First of all, SparsMatrix is never called so the array isn't initialized. Second, you might consider using a list instead of an array because a list will expand as needed and therefor more efficient.
Add these imports:
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
Change the array declaration to a generic list:
List smArray<matrixterm> = new ArrayList<matrixterm>();</matrixterm></matrixterm>
Change the MatrixTerm to add a constructor:
public class MatrixTerm {
public int row,col,value;
public MatrixTerm(int row, int col, int value) {
this.row = row;
this.col = col;
this.value = value;
}
}
Add values to smArray like this:
smArray.add(new MatrixTerm(row, col, value));
Good luck!