【发布时间】:2020-12-20 16:41:45
【问题描述】:
我正在制作类似于 tic tac toe 的东西,一切正常,但除此再次播放按钮之外的所有内容都无法正常工作,并使整个应用程序崩溃。我尝试再次制作它,并尝试制作一个单独的方法来在按下时记录它并且它正在工作,但它不能与再次播放按钮一起工作。
下面是我的播放按钮代码以及代码图片以及单击按钮时发生的错误。
public void playAgain(View view) {
Button playButton = (Button) findViewById(R.id.playButton);
TextView winnerView = (TextView) findViewById(R.id.winnerView);
playButton.setVisibility(View.INVISIBLE);
winnerView.setVisibility(View.INVISIBLE);
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
for(int i = 0; i < gridLayout.getChildCount(); i++) {
ImageView counter = (ImageView) gridLayout.getChildAt(i);
counter.setImageDrawable(null);
}
Arrays.fill(gameState, 2);
activePlayer = 0;
gameActive = true;
}
【问题讨论】:
-
我会说您已经导入或使用了错误版本的
GridLayout作为XML 中的版本和代码中使用的版本不匹配。 (这基本上就是错误日志所说的。) -
@MarkusKauppinen 是的,你是对的,我改了它,它正在工作。
-
请将代码和堆栈跟踪作为文本粘贴到问题中。不要张贴文字图片。它们难以阅读且无法搜索。