简体   繁体   中英

Java Array concept

 for(int m=0; m< checkBoxValue.length ; m++)
 {
    System.out.println("check box in model class"+checkBoxValue[m]+"\n");

 }

This loop is to print two values in array. It prints the values But after that it shows array out of bound exception

It seems you're on the wrong track. It's best to set a breaking point on your for loop and debug your code, then go through it step wise. This will reveal where the exception is thrown...

Especially since you say " after that ", you might want to review your code after that for loop :-)

您确定在这里引发了异常吗?

Ohh.. Looks like a mess. The information looks very abstract. You need to be specific, may be you can give more code over here. One possible cause I think of, may be, is Multi-threading.

Only multi-threaded application can do this trick . If so, you better provide synchronization on the origin object of checkBoxValue variable.

Hope that helps....

只要您正确完成了数组初始化,代码就可以正常工作。

The posted code should not throw ArrayIndexOutOfBoundsException. Most likely, you are doing something after the loop which accesses an incorrect index of an array.

The only way that the code shown in the question could throw an ArrayIndexOutOfBoundsException is if the toString() method of one of the checkBoxValue[m] objects throws the exception.

Maybe you have overridden the toString() method of the checkBoxValue -class (the array initializer would help identifying this class). Following this theory, the toString() implementation might work fine for the first two elements of the array (they are printed) and may throw an exception for the third element in the array.

This could lead to the error description: This loop is to print two values in array. It prints the values But after that it shows array out of bound exception

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM