"Kan ikke tilbakestilles - ingen transaksjoner er aktiv (kode 1)" når du bruker Android Room-biblioteket på API 23-enheten

stemmer
0

Jeg får denne feilen når jeg kjører appen min på en API 23-enhet ved å bruke Room-biblioteket. Det skjer ved første lansering, men jeg kan ikke komme forbi introduksjonen min i appen fordi det skjer hver gang.

Fatal Exception: android.database.sqlite.SQLiteException: cannot rollback - no transaction is active (code 1)
       at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:553)
       at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:439)
       at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
       at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:262)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
       at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:92)
       at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:53)
       at androidx.room.SQLiteCopyOpenHelper.getWritableDatabase(SQLiteCopyOpenHelper.java:90)
       at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
       at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
       at com.diamonddevelopment.cardapp.data.CardMasterDao_Impl.getAllTags(CardMasterDao_Impl.java:1381)
       at com.diamonddevelopment.cardapp.data.AppRepository.getAllTags(AppRepository.kt:158)
       at com.diamonddevelopment.cardapp.activities.MainActivity$Companion$loadTags$1.run(MainActivity.kt:316)
       at java.lang.Thread.run(Thread.java:818)

Dette forekommer ikke på API 24 og over. Er det en feil? Slik lager jeg romdatabasen min:

fun getAppDatabase(context: Context): CardMasterDatabase? {
            if (INSTANCE == null) {
                INSTANCE = Room.databaseBuilder(context.applicationContext, CardMasterDatabase::class.java, FILE_NAME).createFromAsset(databases/$FILE_NAME).build()
            }
            return INSTANCE
        }

Og hvordan jeg bruker det:

 private var cardMasterDao: CardMasterDao? = null

    init {
        cardMasterDao = when {
            CardMasterDatabase.INSTANCE != null -> {
                CardMasterDatabase.INSTANCE!!.cardMasterDao()
            }
            else -> {
                CardMasterDatabase.getAppDatabase(context)!!.cardMasterDao()
            }
        }
    }
Publisert på 18/05/2020 klokken 07:45
kilden bruker
På andre språk...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more