我正在 AsyncTask 中从数据库中检索数据。有时它可以完美地检索数据,但有时会引发以下异常。
08-08 12:14:13.140: E/AndroidRuntime(3659): FATAL EXCEPTION: AsyncTask #5
08-08 12:14:13.140: E/AndroidRuntime(3659): java.lang.RuntimeException: An error occured while executing doInBackground()
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-08 12:14:13.140: E/AndroidRuntime(3659): at java.lang.Thread.run(Thread.java:1019)
08-08 12:14:13.140: E/AndroidRuntime(3659): Caused by: android.database.sqlite.SQLiteMisuseException: library routine called out of sequence: , while compiling: SELECT _id, puzzle_number, path FROM puzzle_file_infors ORDER BY puzzle_number
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
08-08 12:14:13.140: E/AndroidRuntime(3659): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
这是我的异步任务
public class BackgroundTask extends AsyncTask<String, Void, Cursor>{
private final ProgressDialog m_cProgressDialog = new ProgressDialog(m_cContext);
@Override
protected void onPreExecute() {
m_cProgressDialog.setMessage("Please Wait....");
m_cProgressDialog.show();
}
@Override
protected Cursor doInBackground(String... params) {
m_cAdapter.open();
m_cCursor = m_cAdapter.getAllPuzzles();
startManagingCursor(m_cCursor);
return m_cCursor;
}
@Override
protected void onPostExecute(Cursor result) {
startManagingCursor(result);
if(result != null){
m_cPuzzlesAdapter = new PuzzlesAdapter(PuzzlesActivity.this, result, m_cFromActivity);
m_cGridView.setAdapter(m_cPuzzlesAdapter);
m_cAdapter.close();
if (m_cProgressDialog.isShowing()) {
m_cProgressDialog.dismiss();
}
}
}
}
我哪里错了?是不是因为我没有在适当的位置关闭光标?为此,我使用了startManagingCursor(),但它仍然无法正常工作。请指导我。