我將每條數(shù)據(jù)進行分割,之后在我的電腦上面運行沒有問題,但是把代碼遷移到別人的電腦上面就報了數(shù)組溢出的 問題。我要進行分割的是這樣的數(shù)據(jù):nf-000001。以中間的"-"作為分割的界限,把數(shù)據(jù)分成"nf"和"000001"。
代碼
for(int i=1;i<rsRows;i++){
String originNum=null;
Cell cell=readsheet.getCell(column,i);
originNum=cell.getContents();//獲得數(shù)據(jù)“nf-000001”
String[] numGoods=originNum.split("-");//數(shù)據(jù)進行分割
list.add(numGoods[1]);//講分割的后半部分添加在一個Array<String> list中
}
錯誤提示:圖片中160行就是報的list.add(numGoods[1])這個語句的錯誤,我看他說是數(shù)組溢出,然而在我的電腦上面沒有出現(xiàn)這個問題,很奇怪,求大神相助!!
走同樣的路,發(fā)現(xiàn)不同的人生
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.
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