,所以我不知道爲什麼即時得到一個outofbound錯誤在這行出界異常,當列表填充物
bCountry = countriesList.get(loc);
在我的菜單IM
要求用戶輸入兩個字母的國家代碼我修剪空格,和隱蔽它爲大寫,因爲整個列表是大寫
然後我沿着代碼作爲arguement通過在構造
public CountryComponent(String bCode) throws IOException
{
all = false;
String aCode = bCode;
getData();
}
所述的getData甲基od從csv文件中提取信息並用數據創建對象,然後調用其他方法向對象中添加附加信息
問題是當我去嘗試繪製特定對象時,其他所有內容是罰款
它似乎只是國家代碼從菜單心不是被鍵入列表中被人發現,和IM不知道爲什麼
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.elementData(ArrayList.java:371)
at java.util.ArrayList.get(ArrayList.java:384)
at CountryComponent.paintComponent(CountryComponent.java:204)
的底線是「紅」色的例外,那裏有一個更大的名單,idk,如果它需要的話。
異常消息說索引是'-1'。無論'countriesList'中有多少物品,這都是無效的。因此例外。使它不是'-1'。也請在將來發布相關代碼,以及有用的信息,例如'countriesList'的大小和'loc'的值(當然,您在異常消息中間接地發佈了後者)。 –
'-1'總是超出範圍。 – nhgrif
http://docs.oracle.com/javase/7/docs/api/java/lang/ArrayIndexOutOfBoundsException.html解釋了ArrayIndexOutOfBoundsException – user1339772