What causes this ArrayIndexOutOfBoundsException?

I'm making a sudoku game for Android but I'm having an issue. The game compiles, but once you get to the game screen and press a button the game crashes. I checked the logcat and these seems to be the errors: 05-04 09:07:41.620: ERROR/AndroidRuntime(325): FATAL EXCEPTION: main 05-04 09:07:41.620: ERROR/AndroidRuntime(325): java.lang.ArrayIndexOutOfBoundsException 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at org.example.fpsudoku.Button.findScreenV(Button.java:59) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at org.example.fpsudoku.Button.onCreate(Button.java:38) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at android.app.Dialog.dispatchOnCreate(Dialog.java:307) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at android.app.Dialog.show(Dialog.java:225) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at org.example.fpsudoku.Game.showButtonOrError(Game.java:181) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at org.example.fpsudoku.SudokuScreen.onTouchEvent(SudokuScreen.java:221) 05-04 09:07:41.620: ERROR/AndroidRuntime(325): at android.view.View.dispatchTouchEvent(View.java:3766) and this is the code that seems to be the problem: findScreenV(); for (int element : usesquare) { if (element != 0) buttons[element - 1].setVisibility(View.INVISIBLE); } setListeners(); } private void findScreenV() { button = findViewById(R.id.button); buttons[1] = findViewById(R.id.button_1); buttons[2] = findViewById(R.id.button_2); buttons[3] = findViewById(R.id.button_3); buttons[4] = findViewById(R.id.button_4); buttons[5] = findViewById(R.id.button_5); buttons[6] = findViewById(R.id.button_6); buttons[7] = findViewById(R.id.button_7); buttons[8] = findViewById(R.id.button_8); buttons[9] = findViewById(R.id.button_9);
We miss two important things - what is the size of buttons array and what is the size of usesquare?

以上就是What causes this ArrayIndexOutOfBoundsException?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏