不断超越界限异常,不知道为什么?

问题描述:

我正在做一个3维的tic tac脚趾游戏。游戏完成并且工作正常,但是,作业要求(用于测试游戏情况)程序将文件放置在游戏板上的整数文件中。它从Unix命令行获取文件。不断超越界限异常,不知道为什么?

但是,如果没有文件在命令行输入,游戏应该从开始运行。我得到了一个越​​界例外,不知道为什么我的生活。任何帮助将不胜感激。

部分代码用于获取文件和存储整数:

public class Test { 
    static int board[][][] = new int[4][4][4]; 
    static boolean ComputerMoved = false; 
    static int[] sums = new int[76]; 
    static int n = 0; 

    public static void main(String[] args) throws FileNotFoundException { 
     //Method purpose is to look and see if there is a startup file given to 
     //initally setup the board. If not, plays an empty board and prompts the 
     //user for the first move. 

     Scanner scan = new Scanner(new FileInputStream(args[0])); 

      if (args.length > 0) { 
       int size = scan.nextInt(); 
       for (int i = 0; i < size; i++) { 
        int level = scan.nextInt(); 
        int row = scan.nextInt(); 
        int column = scan.nextInt(); 
        int value = scan.nextInt(); 

        level = level % 4; 
        row = row % 4; 
        column = column % 4; 

        board[level][row][column] = value; 
       } 
      } 

提示:看来,越界异常不会从你的阵列来了,而是你的扫描仪。有没有可能你没有足够的数字来扫描?

+0

我明白我做错了什么。在检查长度之前,我正在使用阵列中的第一个位置。谢谢! – NoviceProgrammer123