我将每条数据进行分割,之后在我的电脑上面运行没有问题,但是把代码迁移到别人的电脑上面就报了数组溢出的 问题。我要进行分割的是这样的数据:nf-000001。以中间的"-"作为分割的界限,把数据分成"nf"和"000001"。
代码
for(int i=1;i<rsRows;i++){
String originNum=null;
Cell cell=readsheet.getCell(column,i);
originNum=cell.getContents();//获得数据“nf-000001”
String[] numGoods=originNum.split("-");//数据进行分割
list.add(numGoods[1]);//讲分割的后半部分添加在一个Array<String> list中
}
错误提示:图片中160行就是报的list.add(numGoods[1])这个语句的错误,我看他说是数组溢出,然而在我的电脑上面没有出现这个问题,很奇怪,求大神相助!!
Set a breakpoint. You will know during debugging that the array is out of bounds. Before printing
rsRows
里面是否有没有-
的情况,你在numGoods[1]
, you should at least check the length of the array for the sake of code robustness.Too little relevant information given...
After splitting, judge the length of the numGoods array. It may be that the length of the numGoods element group is less than 2.
I guess the string entered on this computer is not a string connected by "-".
You need to see the - symbol clearly. There are shorter ones and longer ones. Make sure you input it correctly