无法从cursowWindow读取第0行,第-1列

时间:2014-05-21 13:57:22

标签: android android-sqlite android-cursor

我的这个功能有问题。

 public ArrayList<Integer> getStopId(long line_id) {

    String selectQuery = "SELECT _ID_STOP FROM TIME WHERE _ID_LINE = " + line_id;
    ArrayList<Integer> stopID = new ArrayList<Integer>();
    Cursor c = myDataBase.rawQuery(selectQuery, null);

    if (c.moveToFirst())
        do {

            stopID.add(c.getInt(c.getColumnIndex("_ID_STOP")));

        } while (c.moveToNext());

    return stopID;
 }

我想获得一个表stopID,它包含查询selectQuery的所有行的值。它返回一个包含1列和24行的表。

当我启动我的应用程序时,它说&#34;无法从具有24行,1列的cursowWindow读取第0行第-1列。

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

解决方案是:

public ArrayList<Integer> getStopId(long line_id) {

String selectQuery = "SELECT _ID_STOP FROM TIME WHERE _ID_LINE = " + line_id;
ArrayList<Integer> stopID = new ArrayList<Integer>();
Cursor c = myDataBase.rawQuery(selectQuery, null);

if (c.moveToFirst())
    do {

        stopID.add(c.getInt(0));

    } while (c.moveToNext());

return stopID;
 }

我刚刚将c.getColumnIndex(&#34; _ID_STOP&#34;)替换为0,它完美无缺。