我正在尝试从 SQLite 数据库获取 checkTextView 状态,但它导致应用程序崩溃。
这里是实现的代码:
Cursor c = db.rawQuery("SELECT * FROM list", null);
int foundIndex = c.getColumnIndex("found");
while (c != null) {
c.getString(foundIndex);
c.moveToNext();
}
String[] foundList = new String[foundIndex];
arrayAdapter.notifyDataSetChanged();
for (String found : levelOneListList){
if (levelOneListList == foundList){
levelOneListView.setItemChecked(found.indexOf(foundIndex), true);
}
}
}
它给出了这个错误:
java.lang.RuntimeException:无法启动 Activity ComponentInfo{com.example.woodlandwanderer/com.example.woodlandwanderer.levelOneActivity}:android.database.CursorIndexOutOfBoundsException:请求索引 -1,大小为 0
最佳答案
正如错误所示,您的光标大小为 0,并且您正在尝试首先访问。
在循环之前添加以下检查。
if (c.moveToNext() && c.getCount()>0) {
关于java - 尝试从 SQLite DB 设置 checktextview 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58168689/