2011-04-29 37 views
1

我試圖用一個rawQuery與simpleCursorAdapter顯示到ListView,但它一直扔我一個錯誤安卓:sqlite的rawQuery超出範圍

04-29 13:36:36.453:ERROR/AndroidRuntime(29539):java.lang.RuntimeException:無法啓動活動ComponentInfo {com.QuoteMachine/com.QuoteMachine.Quote}:android.database.sqlite.SQLiteException:綁定或列索引超出範圍:句柄0x2f65e0

我有一個表名爲行_id,auth_name,報價,類別和我的查詢看起來如下

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes", 
      new String[]{"WHERE auth_name = 'Robert Anton Wilson'"}); 

可能有人知道一個建議來解決這個問題嗎?我最初的計劃是使用一個基本的查詢語句,但列_id有問題,並且建議我採用這種方法。

回答

4

您使用rawQuery()是錯誤的。第二個變量是用於參數的,而不是WHERE子句。就用它來:

return qmDB.rawQuery("SELECT _id as _id, auth_name, quote, category FROM Quotes WHERE auth_name = ?", 
      new String[] { "Robert Anton Wilson" });