Java—很难弄清楚为什么会有';我的缓存模拟中正在发生一个BoundsException数组

Java—很难弄清楚为什么会有';我的缓存模拟中正在发生一个BoundsException数组,java,exception,caching,simulation,Java,Exception,Caching,Simulation,这种方法应该是: 浏览一个包含32行10个十六进制字符串的文本文件 使用空格作为分隔符将它们分开 将十六进制字符串存储在具有10个索引的数组中 因为我在模拟内存,所以我将数组加载到一个模拟寄存器类中 我已经完成了这一步,但是我很难理解为什么arrayString[]数组会发生arrayOutOfBounds异常 public void setRegister(Register[] r) throws FileNotFoundException{ //pokes through the

这种方法应该是:

  • 浏览一个包含32行10个十六进制字符串的文本文件

  • 使用空格作为分隔符将它们分开

  • 将十六进制字符串存储在具有10个索引的数组中

  • 因为我在模拟内存,所以我将数组加载到一个模拟寄存器类中

  • 我已经完成了这一步,但是我很难理解为什么arrayString[]数组会发生arrayOutOfBounds异常

    public void setRegister(Register[] r) throws FileNotFoundException{ //pokes through the 
                                                                        //file and extracts hexes
    
        Scanner s = new Scanner("/Users/adpitt/Documents/document.txt"); //macOS path
        Register reggie = new Register(); //holding reg
    
        while (s.hasNextLine()) {
        String str = s.nextLine(); //slam a line into the string
    
             for(int i = 0; i <= mainMemSize-1; i++){ //iterate through array of registers
    
                 for(int j = 0; j <= this.length-1; j++){
    
                     String arrayString[] = str.split("\\s+");//smash them to     
                                                              //pieces, space = delimiter
    
                     reggie.reg[j] = arrayString[j];//THIS IS WHERE THE EXCEPTION OCCURS. 
                                                    //I believe it's in arrayString[j], 
                                                    //not sure why.
    
                  }//complete reggie!
                 r[i] = reggie;//load reggie into the register array to complete mm
              }
         }
        s.close();
    
    }
    
    public void setRegister(Register[]r)抛出FileNotFoundException{//poke通过
    //文件并提取hexes
    Scanner s=new Scanner(“/Users/adpitt/Documents/document.txt”);//macOS路径
    Register reggie=new Register();//holding reg
    而(s.hasNextLine()){
    String str=s.nextLine();//在字符串中插入一行
    
    for(int i=0;i为什么要在内部循环中拆分
    str
    ?for循环中的
    str
    值没有变化。能否尝试将其移出for循环,并在
    String str=s.nextLine();

    还有什么是
    this.length
    ?如果
    this.length-1
    大于10(假设str.split返回10个十六进制字符串,根据您的初始描述),该怎么办