2013-03-12 51 views
0

我想展示一个ExpandableListView使用ExpandableListAdapter。我有几个问题。首先是使用UNION如下:使用union clause抛出异常时使用ExpandableListAdapter

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编辑器完美尝试。最后,我可以让它工作改变“联盟”为“联盟”(我仍然不知道为什么)。

下一个问题(仍未解决)来了,当我试图订购的元素。我用了下一句话:

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); 

任何人都可以给小费?

在此先感谢。

回答

0
"union all"+"select .... 

结果union allselect ..

你需要工会之间的空间中的所有选择

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

或只是"union all select ..."

+0

此外,你必须“由2阶” ..不知道你想那里做什么? – dymmeh 2013-03-12 19:54:05

+0

对不起,对不起。编辑代码发布我的答案我把“union all”+“select ...”,但这句话在我的真实代码中是正确的(我编辑了我的问题以纠正这个错误)。问题不在于这个句子,因为当这种情况发生时你会得到一个sql sintax错误。 – Martillador81 2013-03-12 20:07:50

+0

我正在尝试ExpandableListView按顺序显示元素(按“nombre”)。没有“order by”条款,一切运作良好,但列出的列表并未订购。 – Martillador81 2013-03-12 20:09:39