I have a class called table
and inside it there is a nested class called Cell
. I am dividing the table
into cells. I want to create an array of the nested class that called Cell
, I referred my self to some explanatory tutorials to know how to instantiate an object from a nested/inner class but, non of them offered any example of how to instantiate an array of a nested class. the below posted are my attempts and eclipse highlights cell = mTable.Cell[27];
with red squiggle
Code: Table_Class:
// declaration
private Table mTable;
private Table.Cell []cell;
...
...
...
package com.example.kotschiena02;
public class Table {
private int table_X1;
private int table_Y1;
private int table_X2;
private int table_Y2;
public Table(int x1, int y1, int x2, int y2) {
this.table_X1 = x1;
this.table_Y1 = y1;
this.table_X2 = x2;
this.table_Y2 = y2;
}
public int getTableWidth() {
return (this.table_X2 - this.table_X1);
}
public int getTableHeight() {
return (this.table_Y2 - this.table_Y1);
}
public int getTable_X1() {
return this.table_X1;
}
public int getTable_Y1() {
return this.table_Y1;
}
public int getTable_X2() {
return this.table_X2;
}
public int getTable_Y2() {
return this.table_Y2;
}
private class Cell {
private int cell_ID;
private int cell_X1;
private int cell_Y1;
private int cell_X2;
private int cell_Y2;
private boolean occupancyState;
public Cell (int id, int x1, int y1, int x2, int y2, boolean occupancyState) {
this.cell_ID = id;
this.cell_X1 = x1;
this.cell_Y1 = y1;
this.cell_X2 = x2;
this.cell_Y2 = y2;
this.occupancyState = occupancyState;
}
public int getCell_X1() {
return this.cell_X1;
}
public int getCell_Y1() {
return this.cell_Y1;
}
public int getCell_X2() {
return this.cell_X2;
}
public int getCell_Y2() {
return this.cell_Y2;
}
public int getCell_ID() {
return this.cell_ID;
}
public void setOccupancyState(boolean state) {
this.occupancyState = state;
}
public boolean getOccupancyState() {
return this.occupancyState;
}
}
}
Code: SetupTable():
private void setupTable() {
// TODO Auto-generated method stub
Log.i(TAG, "@setupTable:");
mTable = new Table( 10,
((screenHeight/2)-(2*cardHeight)),
(screenWidth-10),
((screenHeight/2)+(2*cardHeight)) );
cell = mTable.Cell[27];