java - 数组溢出问题,在自己电脑上面不报错,在别人电脑上面报错
怪我咯
怪我咯 2017-04-18 10:53:20
0
4
474

我将每条数据进行分割,之后在我的电脑上面运行没有问题,但是把代码迁移到别人的电脑上面就报了数组溢出的 问题。我要进行分割的是这样的数据: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])这个语句的错误,我看他说是数组溢出,然而在我的电脑上面没有出现这个问题,很奇怪,求大神相助!!

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(4)
小葫芦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!