我得到一个例外“SQLiteException:无法提交 - 没有事务处于活动状态”。当我尝试在DataBase中更新我的表时,会发生此异常。我不知道为什么会发生这种异常。这个例外是什么意思。所以如果有人知道那么请告诉我如何解决这个例外。在代码中,当我替换更新查询以插入查询时,不会发生错误。我的更新查询就像
e.g
ContentValues cVal=new ContentValues();
cVal.put("search", 0);
int count=sqLiteDatabaseWrite.update("TableName", cVal, null,null);
或者尝试这个
sqLiteDatabaseWrite.execSQL("update TableName set search=0");
在这两种情况下都会发生错误。在这里我打印我的logcat。
谢谢
android.database.sqlite.SQLiteException: cannot commit - no transaction is active
at android.database.sqlite.SQLiteStatement.native_executeSql(Native Method)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:89)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1928)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1859)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:683)
at android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:266)
at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:96)
at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1824)
at android.database.sqlite.SQLiteDatabase.update(SQLiteDatabase.java:1775)
at com.ScentSational.SearchProducts.insertIntoProductTable(SearchProducts.java:609)
at com.ScentSational.SearchProducts.parseSearchXml(SearchProducts.java:434)
at com.ScentSational.SearchProducts$Async_SearchParsing.doInBackground(SearchProducts.java:780)
at com.ScentSational.SearchProducts$Async_SearchParsing.doInBackground(SearchProducts.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:252)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
at java.lang.Thread.run(Thread.java:1020)