使用unionable子句在使用ExpandableListAdapter时抛出异常

时间:2013-03-12 19:26:48

标签: android expandablelistadapter

我正在尝试使用ExpandableListAdapter显示ExpandableListView。我有几个问题。第一个使用UNION如下:

    Cursor cur = db.rawQuery("select ig._id, ig.nombre, 0 tipo from InteresGrupo ig where ig.nombre<>'General' "+
                             "union "+
                             "select i._id, i.nombre, 1 tipo from Interes i "+
                             "inner join InteresGrupo g on i.interesGrupo=g._id "+
                             "where g.nombre='General' "+
                             "order by ig.nombre", null);

抛出下一个异常:

Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

SQL在SQLite编辑器中完美地运行。最后,我可以让它改变“UNION ALL”的“UNION”(我仍然不知道为什么)。

当我尝试订购元素时,出现了下一个问题(仍未解决)。我用了下一句话:

    Cursor cur = db.rawQuery("select ig._id, ig.nombre, 0 tipo from InteresGrupo ig where ig.nombre<>'General' "+
                             "union all "+
                             "select i._id, i.nombre, 1 tipo from Interes i "+
                             "inner join InteresGrupo g on i.interesGrupo=g._id "+
                             "where g.nombre='General' "+
                             "order by 2", null);

同样的例外。 SQL语句在SQLite编辑器中再次运行良好,所以我认为在使用适配器的SQL语句时必须有一些限制。

在调用适配器的任何方法之前抛出异常,因此它与适配器内的代码无关,只与SQL语句(我猜)有关。我发生在接下来的三行中的第三行:

    ExpandableListView epView = (ExpandableListView)findViewById(R.id.lvIntereses);
    mAdapter = new MyExpandableListAdapter(cur, this);
    epView.setAdapter(mAdapter);

任何人都可以提示?

提前致谢。

1 个答案:

答案 0 :(得分:0)

"union all"+"select ....

union allselect ..

中的结果

你需要在union all之间留一个空格并选择

实施例。 "union all " + "select ....

或仅"union all select ..."

相关问题