0

这是方法:

 public ArrayList<Integer> getDays() {
    Cursor c = database.rawQuery("SELECT * FROM debt;", null);

    nameList = new ArrayList<String>();
    dayList = new ArrayList<Integer>();

    String indName[] = new String[c.getCount()];
    String indDay[] = new String[c.getCount()];

    int d = 0, j = 0, u = 0;

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        indName[j++] = c.getString(c.getColumnIndex("debt_name")); 
        indDay[d++] = c.getString(c.getColumnIndex("pay_day")); // line 384
    }   

    for (String name : indName) {
        if ((indDay[u] != "") || (indDay[u] != null)) {
            dayList.add(Integer.valueOf(indDay[u++]));

        }
    }
    c.close();

    return dayList;
}

我在第 384 行收到一条错误消息:“无法读取第 0 行,列 -1。确保游标已初始化。”

第 384 行标记在上面。你能找到我在这里想念的东西吗?

4

2 回答 2

2

消除 ; 从您的查询结束:SELECT * FROM debt

调用此行:

//optional
//"this"  is your DBHELPER class
SQLiteDatabase database = this.getWritableDatabase();

用这个替换(标记为块)

if(c.moveToFirst()){
    while(c.moveToNext()) {
            indName[j++] = c.getString(c.getColumnIndex("debt_name"));
            indDay[d++] = c.getString(c.getColumnIndex("pay_day"));

        }   ( Line 386!!! )

}
于 2012-06-08T18:40:09.433 回答
0

放 c.moveToNext();

for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        indName[j++] = c.getString(c.getColumnIndex("debt_name")); 
        indDay[d++] = c.getString(c.getColumnIndex("pay_day")); // line 384

    enter code here// c.moveToNext();
    }   
于 2013-03-21T23:06:42.450 回答