在会议室数据库中未创建mydatabase

时间:2018-09-01 15:21:36

标签: android kotlin android-room

嗨,我正在用kotlin编写我的数据库,并希望将该会议室数据库用于java类。但是在运行它时,它显示未实现myAppdatabase的错误。

这是我的数据库cls

@Database(entities = arrayOf(Feedback::class),version = 1,exportSchema = true)
abstract class MyDatabase : RoomDatabase(){

    abstract fun dao(): Dao

    companion object {

        private var INSTANCE: MyDatabase? = null

         fun getInstance(context: Context): MyDatabase? {


            if (INSTANCE == null) {
                synchronized(MyDatabase::class) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                            MyDatabase::class.java, "feed.db").allowMainThreadQueries()
                            .build()
                }
            }
            return INSTANCE

        }
    }

}

这是我的Java类

context=this.getActivity();
INSTANCE=MyDatabase.Companion.getInstance(context);
myDatabase= Room.databaseBuilder(this.getActivity().getApplicationContext(),MyDatabase.class, "feed.dp").fallbackToDestructiveMigration().build();

0 个答案:

没有答案