用这个语句查询表中的记录:(title中的字段是加过单引号的)
result = mDb.query(TABLE_dict, new String[]{KEY_ROWID, KEY_TITLE, KEY_BODY, KEY_IFNEW}, KEY_TITLE + "=" + title, null, null, null, null, null);
然后
String body = result.getString(result.getColumnIndex(DbAdapter.KEY_BODY));
会报错:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
可以输出:cursor.getCount()结果为1,cursor.getColumnCount()结果为4
(查询的那条记录表中肯定存在)
求大牛帮忙解答!!

解决方案 »

  1.   

    好吧,自己解答了,少了一句result.moveToNext();
      

  2.   

    前后描述也矛盾噢,代码中用result,问题描述却用cursor,明显不是同一个代码吧,另外,DbAdapter.KEY_BODY这个值又是多少?在查询之后,应该:
    if(result.getCount()>0)
    {
        result.moveToFirst();
        String body = result.getString(result.getColumnIndex(DbAdapter.KEY_BODY));
    }
      

  3.   

    为什么要moveToFirst啊,难道一上来就在末尾吗