Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 嵌套for循环中的ArrayIndexOutOfBoundsException?_Java_Indexoutofboundsexception - Fatal编程技术网

Java 嵌套for循环中的ArrayIndexOutOfBoundsException?

Java 嵌套for循环中的ArrayIndexOutOfBoundsException?,java,indexoutofboundsexception,Java,Indexoutofboundsexception,我不知道为什么在嵌套的for循环中有一个ArrayIndexOutOfBoundsException。。。它只打印第一个内部for循环,而不打印外部for循环。 谁能告诉我为什么会这样 public static double weight(){ //int counter = 0; System.out.println("####" + d); while(Math.abs(delta_w) > 0.001){ for(int i = 0; i &

我不知道为什么在嵌套的for循环中有一个
ArrayIndexOutOfBoundsException
。。。它只打印第一个内部for循环,而不打印外部for循环。
谁能告诉我为什么会这样

public static double weight(){
    //int counter = 0;
    System.out.println("####" + d);
    while(Math.abs(delta_w) > 0.001){
        for(int i = 0; i < 33; i++ ){

            for(int j = 0; j < 13; j++ ){

                if(Math.abs(delta_w)!=0){

                    value = d.exData[i][j];    //?

                    y = d.exLabels[i];

                    percep = w * d.exData[i][j];
                    System.out.println(d.exData[i][j]);
                    delta_w = y - percep;

                    w+= delta_w;
//                  counter++;
                    System.out.println("value w " + w);
                }
            }
        }
    }

    return w;
}
公共静态双重(){
//int计数器=0;
System.out.println(“#####”+d);
而(数学绝对值(δw)>0.001){
对于(int i=0;i<33;i++){
对于(int j=0;j<13;j++){
如果(数学绝对值(增量w)!=0){
值=d.exData[i][j];/?
y=d.exLabels[i];
percep=w*d.exData[i][j];
System.out.println(d.exData[i][j]);
delta_w=y-percep;
w+=δw;
//计数器++;
系统输出打印项次(“值w”+w);
}
}
}
}
返回w;
}

最可能的原因是'd.exData.length==1'

为什么假设数组大小为33和13?为什么不使用数组的计数呢

public static double weight(){
    //int counter = 0;
    System.out.println("####" + d);
    while(Math.abs(delta_w) > 0.001){
        for(int i = 0; i < d.exData.length; i++ ){

            for(int j = 0; j < d.exData[i].length; j++ ){

                if(Math.abs(delta_w)!=0){

                    value = d.exData[i][j];    //?

                    y = d.exLabels[i];

                    percep = w * d.exData[i][j];
                    System.out.println(d.exData[i][j]);
                    delta_w = y - percep;

                    w+= delta_w;
                    //counter++;
                    System.out.println("value w " + w);
                }
            }
        }
    }

    return w;
}
公共静态双重(){
//int计数器=0;
System.out.println(“#####”+d);
而(数学绝对值(δw)>0.001){
对于(int i=0;i
数组的大小是多少?您的
exData
exLabels
数组的内容和大小是多少?它们是否在
i
j
达到的值范围内。请指定获取异常的行。完整的错误消息应告诉您导致问题的行和索引。这与数组的大小相结合,应该可以确切地告诉您为什么会出现异常,以及如何修复异常。