Room cannot find implementation

前端 未结 11 1865
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 07:17

I have a problem with testing a Room database: when I run the test, I get this exception:

java.lang.RuntimeException: cannot find implementation for databa         


        
11条回答
  •  悲哀的现实
    2020-12-09 08:07

    I did as everybody said in above answer still no luck.
    The issue on my end was that, I was doing insertion on main thread.

    roomDatabase = Room.databaseBuilder(DexApplication.getInstance(),MyRoomDatabase.class,"db_name")
                        .fallbackToDestructiveMigration() // this is only for testing, 
                           //migration will be added for release
                        .allowMainThreadQueries() // this solved the issue but remember that its For testing purpose only
                        .build();
    

    Explanation:

    .allowMainThreadQueries() 
    

    allows you run queries on the main thread. But keep in mind to remove it and implement, RxJava, Live Data or any other background process mechanism for querying database. Hope that would help.

提交回复
热议问题