ArrayIndexOutOfBoundsException when initializing a 2dimensional array of objectts

前端 未结 4 1747
盖世英雄少女心
盖世英雄少女心 2021-01-29 02:40

I have a very simple question but i can\'t figure out why I\'m having this exception. I\'m trying to create a 2-dimensional Array of objects for a sudoku puzzle, but when I\'m i

4条回答
  •  滥情空心
    2021-01-29 03:31

    Initialize lines before creation of array. Now you creating array with 0x0 dimensions, because lines is 0 be default.

    lines = 10; // Add this line   
    grid = new Cell[lines][lines];
    

提交回复
热议问题