WordDatabase_Impl does not exist

在kotlin项目中使用Androidx中的room实现数据库存储的时候,编译运行的时候报了这个错误:(WordDatabase_Impl does not exist)

2020-05-19 14:31:40.591 31419-31419/com.nan.custom_view E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.nan.custom_view, PID: 31419
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nan.custom_view/com.nan.custom_view.DaoActivity}: java.lang.RuntimeException: cannot find implementation for com.nan.custom_view.dao.WordDatabase. WordDatabase_Impl does not exist
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2949)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3027)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1745)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:200)
        at android.app.ActivityThread.main(ActivityThread.java:6956)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
     Caused by: java.lang.RuntimeException: cannot find implementation for com.nan.custom_view.dao.WordDatabase. WordDatabase_Impl does not exist
        at androidx.room.Room.getGeneratedImplementation(Room.java:94)
        at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:952)
        at com.nan.custom_view.DaoActivity.onCreate(DaoActivity.kt:28)
        at android.app.Activity.performCreate(Activity.java:7225)
        at android.app.Activity.performCreate(Activity.java:7216)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1215)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2902)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3027) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1745) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:200) 
        at android.app.ActivityThread.main(ActivityThread.java:6956) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836) 

解决方法:(在APP的build.gradle中添加)

apply plugin: 'kotlin-kapt'
...
dependencies {
    kapt   "androidx.room:room-compiler:2.2.5"//版本看情况吧
}

再次编译,又报了这个错:

e: [kapt] An exception occurred: java.util.NoSuchElementException: Collection contains no element matching the predicate.

检查代码发现某个Entity有一个无参构造方法,这个构造方法需要删除了。

你可能感兴趣的:(WordDatabase_Impl does not exist)