0

我正在为 Android 开发一个字典应用程序,并希望使用CWAC LoaderEx 库来处理 SQL grunt 工作。我的加载器初始化得很好(它使用我在 onCreateLoader 中指定的 SQL 语句填充 listView),但我不知道如何重置加载器以使用用户的搜索词运行另一个查询。

我尝试在 onQueryTextChange 中运行execSQL ( )以启动对用户输入的每个字符的搜索:

loader.execSQL(sqlStatement, new String[] { query + "%" });

但是应用程序崩溃并出现以下错误:

03-04 12:10:36.310: E/AndroidRuntime(15293): FATAL EXCEPTION: AsyncTask #4
03-04 12:10:36.310: E/AndroidRuntime(15293): java.lang.RuntimeException: An error occured while executing doInBackground()
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.os.AsyncTask$3.done(AsyncTask.java:299)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.lang.Thread.run(Thread.java:856)
* 03-04 12:10:36.310: E/AndroidRuntime(15293): Caused by: android.database.sqlite.SQLiteException: unknown error (code 0): Queries can be performed using SQLiteDatabase query or rawQuery methods only.
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1665)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1644)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at com.commonsware.cwac.loaderex.SQLiteCursorLoader$ExecSQLTask.doInBackground(SQLiteCursorLoader.java:188)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at com.commonsware.cwac.loaderex.SQLiteCursorLoader$ExecSQLTask.doInBackground(SQLiteCursorLoader.java:1)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-04 12:10:36.310: E/AndroidRuntime(15293):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-04 12:10:36.310: E/AndroidRuntime(15293):    ... 4 more

根据LoaderEx 文档,我应该能够以这种方式使用 execSQL 来重用现有的 SQLiteCursorLoader。我是否误解了文档?我究竟做错了什么?

4

1 回答 1

4

您的 SQL 语句显然返回了一个结果集。这是不允许execSQL()SQLiteDatabase。这与SQLiteCursorLoader.

于 2013-03-04T20:39:21.903 回答