2011-10-04 77 views
0

我偶然發現了一個我現在弄不清楚的問題。當我將一個包傳遞給一個新的活動時,我得到一個索引越界異常。android indexoutofboundsexception通過意圖傳遞包

我使用下面的代碼:

Intent intent = new intent(this, statelistactivity.class); 

Bundle bundle = new bundle(); 
Bundle.putInt("id", _id); 
Bundle.putString("name", _name); 
Intent.putExtras(bundle); 

startactivity(intent); 

在我使用接收活動:

String name = getIntent().getString("name); 

以下爲INT同樣的原則。

但是我的代碼從來沒有到達這裏,因爲outofboundsexception。什麼會造成這種情況?

+0

發佈您的LogCat輸出。 –

+0

據我所知,outofbounds異常通常會在有數組或列表時出現,並且您正在嘗試訪問一個不在此數組範圍內的iten – 2011-10-04 07:56:15

+1

我不認爲這個代碼甚至編譯了 – Caner

回答

0

我找到了自己的解決方案。這與我所懷疑的完全不同。

我有一個循環運行某個地方的應用程序的完全不同的部分。但在程序中。錯誤駐留在那裏。在源頭深處,它實際上是一個導致它的數組列表。感謝您的時間和答覆。

0

你並沒有試圖從你放入字符串的包中獲取字符串。 你應該嘗試獲得第一包,並從包獲得所有變量 -

Bundle b = getIntent().getExtras(); 
String name = b.getString("name"); 
+0

謝謝:)它不解決它。我認爲這個錯誤有一個更深的根源 –