2011-09-17 76 views
1

PLZ的幫助我,我面對這個問題android.database.CursorIndexOutOfBoundsException:指數-1要求,大小5

我的代碼是

`final Cursor curr = dbhelper.getdatatomanagedata(); 
startManagingCursor(curr); 
Integer colid = curr.getInt(0); 
String colans = curr.getString(1); 
objansMap = new HashMap<Integer, String>(); 
if (curr!=null) 
{ 
curr.moveToFirst(); 
while(!curr.isAfterLast()) 
{ 
    objansMap.put(colid, colans); 
    curr.moveToNext(); 
}} 
+0

把你的SQL查詢,如果要設置光標記錄的代碼,以便我們能找到什麼是你的代碼錯誤? –

回答

3

您的代碼必須是

final Cursor curr = dbhelper.getdatatomanagedata(); 
startManagingCursor(curr); 
Integer colid; 
String colans; 
objansMap = new HashMap<Integer, String>(); 
if (curr!=null) 
{ 
curr.moveToFirst(); 
while(!curr.isAfterLast()) 
{ colid = curr.getInt(0); 
    colans = curr.getString(1); 
    objansMap.put(colid, colans); 
    curr.moveToNext(); 
}} 

當遊標返回其默認索引爲-1時,您必須使用moveToFirst()移至其第0個索引。

另一種方式來使用你的代碼

if(cur.moveToFirst()){ 
     do{ 
      //YOUR CODE HERE 
      objansMap.put(curr.getInt(0), curr.getString(1));    
     }while(cur.moveToNext()); 
    } 

編碼愉快:)

+0

hey pankaj thnx .its解決使用上面的代碼...... :) – Piyush

相關問題