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);
任何人都可以給小費?
在此先感謝。
此外,你必須「由2階」 ..不知道你想那裏做什麼? – dymmeh 2013-03-12 19:54:05
對不起,對不起。編輯代碼發佈我的答案我把「union all」+「select ...」,但這句話在我的真實代碼中是正確的(我編輯了我的問題以糾正這個錯誤)。問題不在於這個句子,因爲當這種情況發生時你會得到一個sql sintax錯誤。 – Martillador81 2013-03-12 20:07:50
我正在嘗試ExpandableListView按順序顯示元素(按「nombre」)。沒有「order by」條款,一切運作良好,但列出的列表並未訂購。 – Martillador81 2013-03-12 20:09:39