いくつかのデータをループしてArrayList<ArrayList<Cell>>、各ステップのを作成しています。各Cellクラスは(とりわけ)rowとを格納します。col
私の問題は、listOfCells後で調査すると、すべてCellのオブジェクトが同じ行(の最後の行)を持っていることですmyData。これは、でのみ発生し、列は本来あるrowべき状態になります(つまり、独自の列になります)。row適切にインクリメントしますが、そうすると、のすべての値が変更rowされますlistOfCells。
何が原因なのかわかりません。
Cellの作成
Cell cell = null;
int row = 0;
int col = 0;
ArrayList<Cell> tmpCellList = new ArrayList<Cell>();
ArrayList<ArrayList<Cell>> listOfCells = new ArrayList<ArrayList<Cell>>();
for (ArrayList<double> eachRow : myData) {
row++;
for (double eachCol : eachRow) {
col++;
cell = new Cell();
cell.setCol(col);
cell.setRow(row);
cell.setValue(eachCol);
tmpCellList.add(cell);
}
listOfCells.add(row-1, tmpCellList);
}
Cellクラス
public class Cell {
private int row;
private int col;
private double value;
public void setRow(int rowIn) {
this.row = rowIn;
}
public int getRow() {
return row;
}
public void setCol(int colIn) {
this.col = colIn;
}
public int getCol() {
return col;
}
public void setValue(double val) {
this.value = val;
}
public double getValue() {
return value;
}