Help in array of array of classes needed

  • Thread starter Thread starter razovy
  • Start date Start date
R

razovy

I want to create class Matrix which contains array of class Rows.
Class Rows contains array of Cells.

Here is the declaration:

public class Cells
{
public int value = 0;
public int color = 0;
public int background = 0;

}
public class Rows
{
public Cells [] cell = new Cells [10];
public int row_num;
}

public class Matrix
{
public Rows []row = new Rows [100];
public int new_id;
// Constructor
public Matrix (){
. . .
for (int i=0; i<10; i++){
for (int j=0; j<10; j++){
row.cell[j] = i+j;
}
}
. . .
}

}



Creation of class Matrix element

Matrix mtr = new Matrix();


causes Error in Constructor in “row.cell[j] = i+j;”
“Object reference not set to an instance of an object”.
Rows are nulls and Cells are missing entirely when I tried to watch an
Object!!!

Obviously something missing in Constructor, but I have no idea how to
fix it.

Please help

:cry:
 
Back
Top