Android studio 文件室无法验证数据完整性,空数据崩溃

Android studio 文件室无法验证数据完整性,空数据崩溃,android-studio,kotlin,android-fragments,android-recyclerview,android-room,Android Studio,Kotlin,Android Fragments,Android Recyclerview,Android Room,我正在开发Android应用程序,通过存储中的特定路径从房间数据库中获取特定数据。我的应用程序崩溃了,因为它在存储器中没有任何数据,Logcat给了我这个 java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this b

我正在开发Android应用程序,通过存储中的特定路径从房间数据库中获取特定数据。我的应用程序崩溃了,因为它在存储器中没有任何数据,
Logcat
给了我这个

 java.lang.IllegalStateException: Room cannot verify the data integrity. Looks like you've changed schema but forgot to update the version number. You can simply fix this by increasing the version number.
    at androidx.room.RoomOpenHelper.checkIdentity(RoomOpenHelper.java:154)
    at androidx.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:135)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:195)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:428)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:317)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:145)
    at androidx.sqlite.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:106)
    at androidx.room.RoomDatabase.inTransaction(RoomDatabase.java:476)
    at androidx.room.RoomDatabase.assertNotSuspendingTransaction(RoomDatabase.java:281)
    at com.maximus.technologies.views.activities.scanneddatabase.TodoDaoScanned_Impl.getAllScan(TodoDaoScanned_Impl.java:152)
    at com.maximus.technologies.views.fragments.scanhistorypackage.QRRetrievingScanClassPresenter$getAllDatFromDatabase$1.invokeSuspend(QRRetrievingScanClassPresenter.kt:29)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:241)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
上述错误或崩溃仅在应用程序存储中没有任何数据时发生。但当我输入数据时,崩溃问题得到了解决

我无法理解问题到底是什么

这是我的房间数据库课

@Database(
entities = [TodoEntity::class,TodoEntityScanned::class],
version = 1)
abstract class AppDatabase : RoomDatabase() {
    abstract fun TodoDao(): TodoDao
    abstract fun TodoDaoScanned(): TodoDaoScanned

object DatabaseBuilder {
    private var INSTANCE: AppDatabase? = null

    fun getInstance(context: Context): AppDatabase {
        if (INSTANCE == null) {
            synchronized(AppDatabase::class) {
                INSTANCE = buildRoomDB(context)
            }
        }
        return INSTANCE!!
    }

    private fun buildRoomDB(context: Context) =
        Room.databaseBuilder(
            context.applicationContext,
            AppDatabase::class.java,
            "mindorks-example-coroutines"
        ).build()
}
}

房间数据库检索接口,其中应用程序在
getall()上崩溃

这是我在
RecyclerView

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    recyclerviewcreatehistory?.layoutManager = LinearLayoutManager(context)
    recyclerviewcreatehistory?.setHasFixedSize(true)
    filefetch()
    customAdaptercreatehistory = CustomAdapterCreateHistory(this.context ?: return, charItemcreate!!,this)
    recyclerviewcreatehistory?.adapter = customAdaptercreatehistory
}

fun filefetch() {
    val noteDatabase: AppDatabase = AppDatabase.DatabaseBuilder.getInstance(requireContext())
    retrivingpresenter = QRRetrievingClassPresenter(this)
    retrivingpresenter!!.getAllDatFromDatabase(noteDatabase)
}
override fun showAllData(note_list: List<TodoEntity>) {
    if (note_list is ArrayList<*>) {
    val arraylist = note_list as ArrayList<TodoEntity>
    charItemcreate=arraylist
    }
    if (charItemcreate.isEmpty()){
    }else{
        customAdaptercreatehistory?.updateUsers(note_list as ArrayList<TodoEntity>)
        customAdaptercreatehistory?.notifyDataSetChanged()
       // Log.d("hello", note_list[0].imagesPathData)
    }
}
覆盖已创建的视图(视图:视图,savedInstanceState:Bundle?){
super.onViewCreated(视图,savedInstanceState)
RecycleServiceCreateHistory?.layoutManager=LinearLayoutManager(上下文)
RecycleServiceCreateHistory?.setHasFixedSize(真)
filefetch()
customAdaptercreatehistory=customAdaptercreatehistory(this.context?:return,charItemcreate!!,this)
RecycleServiceCreateHistory?.adapter=customAdaptercreatehistory
}
fun filefetch(){
val noteDatabase:AppDatabase=AppDatabase.DatabaseBuilder.getInstance(requireContext())
RetrievingPresenter=QRRetrievingClassPresenter(此)
检索演示者!!.getAllDatFromDatabase(noteDatabase)
}
覆盖所有数据(注:列表){
如果(注意:列表为ArrayList){
val arraylist=注释\u列表为arraylist
charItemcreate=arraylist
}
if(charItemcreate.isEmpty()){
}否则{
customAdaptercreatehistory?.updateUsers(注意列表为ArrayList)
customAdaptercreatehistory?.notifyDataSetChanged()
//Log.d(“你好”,注意事项列表[0]。imagesPathData)
}
}

您必须在协同程序中的getAllDatFromDatabase()中进行一些检查。我猜列表变量等于null或者类似的东西。你应该检查是否有任何文件,如果没有,你需要把其他东西放在那里

interface TodoDao {
@Query("SELECT * FROM tablefilepaths")
fun getAll(): List<TodoEntity>

@Query("SELECT * FROM tablefilepaths WHERE imagespath LIKE :title")
fun findByTitle(title: String): TodoEntity

@Insert
fun insertpaths(todo: TodoEntity)

@Delete
fun deletepaths(todo: TodoEntity)

@Query("DELETE FROM tablefilepaths WHERE id = :noteId")
fun deleteNoteById(noteId: Int)

@Update
fun updateTodo(vararg todos: TodoEntity)}
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    recyclerviewcreatehistory?.layoutManager = LinearLayoutManager(context)
    recyclerviewcreatehistory?.setHasFixedSize(true)
    filefetch()
    customAdaptercreatehistory = CustomAdapterCreateHistory(this.context ?: return, charItemcreate!!,this)
    recyclerviewcreatehistory?.adapter = customAdaptercreatehistory
}

fun filefetch() {
    val noteDatabase: AppDatabase = AppDatabase.DatabaseBuilder.getInstance(requireContext())
    retrivingpresenter = QRRetrievingClassPresenter(this)
    retrivingpresenter!!.getAllDatFromDatabase(noteDatabase)
}
override fun showAllData(note_list: List<TodoEntity>) {
    if (note_list is ArrayList<*>) {
    val arraylist = note_list as ArrayList<TodoEntity>
    charItemcreate=arraylist
    }
    if (charItemcreate.isEmpty()){
    }else{
        customAdaptercreatehistory?.updateUsers(note_list as ArrayList<TodoEntity>)
        customAdaptercreatehistory?.notifyDataSetChanged()
       // Log.d("hello", note_list[0].imagesPathData)
    }
}