Android onUpgrade endTransaction的数据库调用导致illegalStateException

时间:2013-03-17 20:16:02

标签: android

不久前我发布了这个问题: Android onUpgrade Database causing IllegalStateException

灵魂化是在db升级时停止并重新启动事务:

public void onUpgrade(SQLiteDatabase db,
        int oldVersion, int newVersion) {

db.endTransaction();
//updgading the db
db.beginTransaction();
}

这对我的测试系统起作用,但现在我从生命系统中获得永久性错误痕迹。 似乎它在大多数系统上工作,但不是一个。

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:278)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.IllegalStateException: no transaction pending
at net.sqlcipher.database.SQLiteDatabase.endTransaction(SourceFile:640)
at net.sqlcipher.database.SQLiteOpenHelper.getWritableDatabase(SourceFile:128)
at com.myApp.j.q(SourceFile:339) ...

这里有什么问题? 谢谢塔塔

编辑:这是发生崩溃的地方。 SQLiteOpenHelper.getWritableDatabase(的SourceFile:128)

int version = db.getVersion();
            if (version != mNewVersion) {
                db.beginTransaction();
                try {
                    if (version == 0) {
                        onCreate(db);
                    } else {
                        onUpgrade(db, version, mNewVersion);
                    }
                    db.setVersion(mNewVersion);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction(); //L. 128 crash
                }
            }

0 个答案:

没有答案