【发布时间】:2015-02-09 01:03:55
【问题描述】:
我有以下代码:
public int[] getState() {
int[] a = new int[SIZE];
for (int i = 0; i < SIZE; i++) { a[i] = mCells[i].getState(); }
return a;
}
public void setState(int player, int[] state){
setCurrentPlayer(player);
//state = new int[9];
// have tried this.getState();
state = getState();
}
但我得到以下编译器错误:
Your code did not compile: /testClass.java:25: cannot find symbol
symbol : method getState()
location: class testClass
state = getState();
^
1 error
我有两个类 CellState :
public int getState(){
return mState;
}
而 GameState 具有第一个 getState 和以下属性:
private CellState[] mCells;
你能建议吗?
提前非常感谢! :)
【问题讨论】:
-
请显示重现编译错误的minimal, complete example。
-
如果您在您的
testClass中调用您的getState(),但它在您的CellState中实现,您应该通过创建CellState的实例来调用它!state = getState();不是正确的做法。 -
您好,我正在使用web IDE(这是我学习android dev的课程),请查看以下链接中的图片link跨度>
-
@OmarBISTAMI
GameState gState = new GameState(); gState.getState();怎么样? -
我在
GameState中还没有构造函数,请注意getState()方法是在GameState类中声明的。您认为问题是由 Web IDE 引起的吗?在我的 android studio 中我没有任何错误(没有测试类)
标签: java class methods int call