2014-02-28 73 views
0

在我的項目中,我正在使用webservices。爲了和他們一起玩,我在java中使用了Hastable。 我使用1.6.x java版本。我有一個哈希表聲明哈希表長度限制java

Hashtable<String, String> props1 = new Hashtable<String, String>(); 

我可以把數據在這樣

props1.put("@aze", values); 

的9個第一要素:沒問題,一切運行良好。在第一次,它崩潰了......我不明白。

我該怎麼辦?

許多THX

編輯:全碼源

public static void main(String[] args) { 

    Hashtable<String, String> props1 = new Hashtable<String, String>(); 
    props1.put("@matricule", values[0]); 
    props1.put("@nom", values[1]); 
    props1.put("@prenom", values[2]); 
    props1.put("@email", values[3]); 
    props1.put("@estoccasionnel", values[4]); 
    props1.put("@adresse", values[5]); 
    props1.put("@codepostal", values[6]); 
    props1.put("@ville", values[7]); 
    props1.put("@telfixe", values[8]); 
    props1.put("@telmobile", values[9]); 
} 

在 props1.put代碼中斷( 「@ telmobile」,值[9]);

與錯誤消息

java.lang.ArrayIndexOutOfBoundsException: 9 
at CommandLineCreationWebservice.main(CommandLineCreationWebservice.java:99) 
+1

顯示您的代碼 – stinepike

+7

我們需要了解您添加的方式和內容,特別是它崩潰的行和錯誤消息的內容。 – libik

+0

+1給libik評論。沒有理由將Hashtable限制爲10條記錄,問題必須在其他地方。 –

回答

3
props1.put("@telmobile", values[9]); 

values數組沒有第10個值。這就是java.lang.ArrayIndexOutOfBoundsException: 9(java中從零開始的索引)的含義

+2

其實它的第10個值和索引號9 –

+1

確實,我會更正我的回答:) –

2

爪哇哈希表能夠存儲大量對象的(取決於你的堆大小)。在任何情況下,它是更多,即10。

0

問題是你的值數組不在哈希表中。 可能你的values數組的大小是不夠的。在這種情況下,它至少應該是10。