开发者

android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 5

plz help me i face this problem

my code is

`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.moveT开发者_开发技巧oNext();
 }}


Your code must be as

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();
 }}

When cursor returns its default index is -1, and you must move to its 0th index by using moveToFirst() .

Another way to use your code as

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

Happy coding :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜