我收到此错误..请帮助我解决此错误或了解原因!
03-18 15:59:39.094: ERROR/AndroidRuntime(480): FATAL EXCEPTION: AsyncTask #2
03-18 15:59:39.094: ERROR/AndroidRuntime(480): java.lang.RuntimeException: An error occured while executing doInBackground()
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at android.os.AsyncTask$3.done(AsyncTask.java:200)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.lang.Thread.run(Thread.java:1019)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): Caused by: java.lang.IllegalStateException: database not open
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1146)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1422)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at aynoo.utility.DBAdapter.insertMessage(DBAdapter.java:67)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at aynoo.utility.Cach.AddMessages(Cach.java:23)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:396)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:1)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): ... 4 more
03-18 15:59:39.484: ERROR/Database(480): close() was never explicitly called on database '/data/data/aynoo.forms/databases/aynoo'
03-18 15:59:39.484: ERROR/Database(480): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
03-18 15:59:39.484: ERROR/Database(480): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1827)
03-18 15:59:39.484: ERROR/Database(480): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
03-18 15:59:39.484: ERROR/Database(480): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
03-18 15:59:39.484: ERROR/Database(480): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
03-18 15:59:39.484: ERROR/Database(480): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:541)
03-18 15:59:39.484: ERROR/Database(480): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
03-18 15:59:39.484: ERROR/Database(480): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
03-18 15:59:39.484: ERROR/Database(480): at aynoo.utility.DBAdapter.open(DBAdapter.java:47)
03-18 15:59:39.484: ERROR/Database(480): at aynoo.utility.Cach.AddMessages(Cach.java:22)
03-18 15:59:39.484: ERROR/Database(480): at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:396)
03-18 15:59:39.484: ERROR/Database(480): at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:1)
03-18 15:59:39.484: ERROR/Database(480): at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 15:59:39.484: ERROR/Database(480): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
03-18 15:59:39.484: ERROR/Database(480): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-18 15:59:39.484: ERROR/Database(480): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-18 15:59:39.484: ERROR/Database(480): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-18 15:59:39.484: ERROR/Database(480): at java.lang.Thread.run(Thread.java:1019)
Cach课在哪里
public class Cach {
static DBAdapter db;
public Cach(Context c)
{
}
public static void AddMessages(Context c,
int id,
int fromId,
int toId,
String message,
String dir,
String MessageTime)
{
db = new DBAdapter(c);
db.open();
db.insertMessage(id, fromId, toId, message, dir,MessageTime);
db.close();
}
}
最佳答案
这听起来很像两个线程(两个并行运行的异步任务?)正在尝试访问数据库。因此,第一个线程具有锁,然后您的Cach.AddMessages()
出现并想要插入数据,因此它尝试获取锁,但失败,因此无法打开数据库,随后的插入失败。