给出绑定异常的数组……。与android中的游标相关

给出绑定异常的数组……。与android中的游标相关,android,cursor,Android,Cursor,只需将条件更改为ifc.moveToFirst,并将while条件设置为末尾,因为否则在从光标获取内容之前,您将移动到下一条语句。您的代码应该如下所示: l = new ArrayList<String>(); db =openOrCreateDatabase("mydb", SQLiteDatabase.CREATE_IF_NECESSARY, null); String sql1 = "create table if not exists word

只需将条件更改为ifc.moveToFirst,并将while条件设置为末尾,因为否则在从光标获取内容之前,您将移动到下一条语句。您的代码应该如下所示:

l = new ArrayList<String>();
        db =openOrCreateDatabase("mydb", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        String sql1 = "create table if not exists words(word text primary key, meaning text not null )";
        db.execSQL(sql1);
        String sql = "select word from words";
        Cursor c = db.rawQuery(sql, null);
        int i=0;
        if (c.isBeforeFirst())
    while(c.moveToNext())
    {
        l.add(c.getString(i));
        i++;
    }

请阅读.07-03 06:40:17.675:E/AndroidRuntime965:java.lang.RuntimeException:无法启动活动组件信息{com.example.dictionary/com.example.dictionary.MainActivity}:java.lang.IllegalStateException:无法从游标窗口读取第1行第1列。在访问数据之前,请确保光标已正确初始化。您阅读了我刚才提供的链接吗?
l = new ArrayList<String>();
db =openOrCreateDatabase("mydb", SQLiteDatabase.CREATE_IF_NECESSARY, null);
String sql1 = "create table if not exists words(word text primary key, meaning text not null )";
db.execSQL(sql1);
String sql = "select word from words";
Cursor c = db.rawQuery(sql, null);
int i=0;
if(c.moveToFirst())
    do
    {
        l.add(c.getString(i));
        i++;
    } while(c.moveToNext())
}