【发布时间】:2015-10-13 11:57:59
【问题描述】:
我正在使用以下代码:
preparePeople();
final Cursor c = mContext.getContentResolver().query(People.CONTENT_URI, mPROJECTION, null, null, null);
String s = c.getString(1);
private void preparePeople() {
final ContentResolver mResolver = mContext.getContentResolver();
mResolver.delete(People.CONTENT_URI, null, null);
final ContentValues valuse = new ContentValues();
valuse.put(People._ID, "1");
valuse.put(People.NAME, "name");
Uri uri = mResolver.insert(People.CONTENT_URI, valuse);
}
但在执行上述代码时,我得到如下异常:
android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 0
这是由于根据日志的 c.getString(1) 语句,但我不知道为什么.. 谁能帮忙解决这个错误?
【问题讨论】:
-
将
String s = c.getString(1);更改为String s = c.getString(0); -
@MD,getString(0) 也有同样的问题,它打印: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
标签: android exception cursor indexoutofboundsexception cts