2 回答
TA貢獻1829條經驗 獲得超4個贊
ArrayIndexOutOfBoundsException 意味著您正在嘗試訪問數組中不存在的元素,即索引大于最后一個元素索引的元素。
String[] someArray = new String[]{"a - index 0", "b - index 1", "c - index 2"};
String inexistent = someArray[3]; //This will throw an ArrayIndexOutOfBoundsException since there are only three elements in the array, the last having index 2 (it always starts at 0 = zero-based)
你的錯誤是
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Subnet.main(Subnet.java:31)
你應該看看Subnet.java文件的第 31 行,看看你是如何計算數組索引的
在該行添加斷點并檢查數組和計算出的索引肯定會有所幫助
TA貢獻1772條經驗 獲得超8個贊
我終于發現了一個小錯誤:
String fip[]={"","",""};它位于完整代碼的中間。問題是我提交了 4 個字符串,但在上面的錯誤代碼行中,我只讓它需要 3 個,答案是我應該再添加一個括號,所以總共 4 個,如下所示:
String fip[]={"","","",""};添加回答
舉報
