Java 如何创建内部类的对象数组?

Java 如何创建内部类的对象数组?,java,android,Java,Android,我有一个名为table的类,其中有一个嵌套的类,名为Cell。我正在将表划分为单元格。我想创建一个名为Cell的嵌套类数组,我参考了一些解释性教程,了解如何从嵌套/内部类实例化对象,但没有一个提供如何实例化嵌套类数组的示例。下面是我的尝试和eclipse亮点cell=mTable.cell[27]带有红色波形 代码:表\u类: // declaration private Table mTable; private Table.Cell []cell; ... ... ... package c

我有一个名为
table
的类,其中有一个嵌套的类,名为
Cell
。我正在将
划分为单元格。我想创建一个名为
Cell
的嵌套类数组,我参考了一些解释性教程,了解如何从嵌套/内部类实例化对象,但没有一个提供如何实例化嵌套类数组的示例。下面是我的尝试和eclipse亮点
cell=mTable.cell[27]带有红色波形

代码:表\u类

// 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;
        }
    }
}
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];
代码:SetupTable()

// 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;
        }
    }
}
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];
公共类表{
//其他属性
私有列表单元;
类单元{
//属性、getter和setter
}
//接球手和接球手
}
//摆桌子
公共void setupTable(){
//TODO自动生成的方法存根
Log.i(标记“@setupTable:”);
表mTable=新表(10,
((屏幕高度/2)-(2*cardHeight)),
(屏幕宽度-10),
((屏幕高度/2)+(2*cardHeight));
Table.Cell Cell=mTable.getCells().get(27);
}

前两个公共类不能在同一个文件中。然后创建一个对象数组就像创建其他数组一样。例如,您可以说mTalbe.Cell[27]=newcell(/parameters,如果需要/);为什么要将此标记为?单元格应标记为staticGlobal声明?在爪哇?你是认真的吗?@nafas将类单元格的修饰符更改为private后,eclipse突出显示了全局声明
private mTable.Cell[]Cell带有红色SQYUGLE