我在我的应用程序上收到此错误,我无法弄清楚它为什么会发生。谷歌上什么都没有
Thread [<1> main] (Suspended (exception ArrayIndexOutOfBoundsException))
ViewRootImpl.deliverInputEvent(ViewRootImpl$QueuedInputEvent) line: 3173
ViewRootImpl.doProcessInputEvents() line: 4292
ViewRootImpl.enqueueInputEvent(InputEvent, InputEventReceiver, int, boolean) line: 4271
ViewRootImpl$WindowInputEventReceiver.onInputEvent(InputEvent) line: 4363
ViewRootImpl$WindowInputEventReceiver(InputEventReceiver).dispatchInputEvent(int, InputEvent) line: 179
MessageQueue.nativePollOnce(int, int) line: not available [native method]
MessageQueue.next() line: 125
Looper.loop() line: 124
ActivityThread.main(String[]) line: 5041
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 511
ZygoteInit$MethodAndArgsCaller.run() line: 793
ZygoteInit.main(String[]) line: 560
NativeStart.main(String[]) line: not available [native method]
我的代码:
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
if(mDelegate != null) {
int size = this.getWidth() / 3; // Board should remain a square
// Get the row and column that was tapped based on the relative tap position
int pointerX = (int)Math.floor((event.getX()) / size);
int pointerY = (int)Math.floor((event.getY()) / size);
Log.i("info", "Pointer x:"+pointerX+" y:"+pointerY);
int index = (pointerY * 3) + pointerX;
if(index >= 0 && index < 9)
mDelegate.onSelectTile(index);
}
}
return true;
}
@Override
public void onSelectTile(int index) {
// TODO Auto-generated method stub
Log.i("info", "Selected tile at index: "+index);
if(mGameBoard[index] != 0)
return;
//mGameBoard.playMove(TURN.TURN_X, index);
if(mTurn == Turn.PLAYER_1) {
mGameBoard[index] = 1;
mTurn = Turn.PLAYER_2;
checkWinningConditions();
mGameBoardView.invalidate();
mTurns++;
} else {
mGameBoard[index] = 2;
mTurn = Turn.PLAYER_1;
checkWinningConditions();
mGameBoardView.invalidate();
mTurns++;
}
}
private void checkWinningConditions() {
// Horizontal victory
for(int i = 0; i < 4; i++) {
if(mGameBoard[i] != 0 && mGameBoard[i] == mGameBoard[i+1] && mGameBoard[i] == mGameBoard[i+2]) {
if(mGameBoard[i] == 1) {
addPlayer1Score();
} else {
addPlayer2Score();
}
resetBoard();
return;
}
}
// Vertical victory
for(int i = 0; i < 4; i++) {
if(mGameBoard[i] != 0 && mGameBoard[i] == mGameBoard[i+3] && mGameBoard[i] == mGameBoard[i+6]) {
if(mGameBoard[i] == 1) {
addPlayer1Score();
} else {
addPlayer2Score();
}
resetBoard();
return;
}
}
// Diagnal
if(mGameBoard[4] != 0 && mGameBoard[0] == mGameBoard[4] && mGameBoard[0] == mGameBoard[8]) {
if(mGameBoard[4] == 1) {
addPlayer1Score();
} else {
addPlayer2Score();
}
resetBoard();
return;
}
if(mGameBoard[4] != 0 && mGameBoard[6] == mGameBoard[4] && mGameBoard[2] == mGameBoard[4]) {
if(mGameBoard[4] == 1) {
addPlayer1Score();
} else {
addPlayer2Score();
}
resetBoard();
return;
}
if(mTurns == 9) {
// NO WINNER
resetBoard();
}
}