kotlin 程序编译期间房间数据库错误

时间:2021-07-18 09:15:29

标签: android kotlin android-room

我有这个模型:

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverter

@Entity(tableName = "ot_tracker_db")
data class OverTime(
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "Id")
    var id: Int,
    @ColumnInfo(name = "Title")
    var title: String,
    @ColumnInfo(name = "StartDateTime")
    var startDateTime: java.util.Date?,
    @ColumnInfo(name = "EndDateTime")
    var endDateTime: java.util.Date?,
    @ColumnInfo(name = "Details")
    var details: String
)

在我的 DAO 中

import androidx.room.*
import kotlinx.coroutines.flow.Flow
import net.androidtries.overtimetracker.Models.OverTime
import java.sql.Date
import java.util.*

@Dao
interface OtTrackerDAO {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertOverTime(overTime: OverTime) : Long

    @Update
    suspend fun updateOverTime(overTime: OverTime) : Int

    @Delete
    suspend fun deleteOverTime(overTime: OverTime) : Int

    @Query("DELETE FROM ot_tracker_db")
    suspend fun deleteAllOverTimes() : Int

    @Query("SELECT * FROM ot_tracker_db")
    fun getAllOvertimes(): Flow<List<OverTime>>

    @Query("SELECT * FROM ot_tracker_db WHERE StartDateTime = :startDateTime")
    fun selectViaStartDateTime(startDateTime: Date): Flow<List<OverTime>>
}

和数据库实现为

@Database(entities = [OverTime::class], version = 1)
@TypeConverters(Converters::class)
abstract class OtTrackerDB : RoomDatabase() {
    abstract val otTrackerDAO: OtTrackerDAO

    companion object{
        @Volatile
        private var INSTANCE: OtTrackerDB? = null
        fun getInstance(context: Context): OtTrackerDB {
            synchronized(this) {
                var instance = INSTANCE
                if (instance == null) {
                    instance = Room.databaseBuilder(
                        context.applicationContext,
                        OtTrackerDB::class.java,
                        "ot_tracker_db"
                    ).build()
                }
                return instance
            }
        }
    }
}

当我构建它时,它给了我一个错误:

> Execution failed for task ':app:kaptDebugKotlin'.
> > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
>    > java.lang.reflect.InvocationTargetException (no error message)

这是我猜的错误:

> Task :app:kaptDebugKotlin FAILED
> D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:13:
> error: Type of the parameter must be a class annotated with @Entity or
> a collection/array of it.
>     kotlin.coroutines.Continuation<? super java.lang.Long> p1);
>                                                            ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:11:
> error: Not sure how to handle insert method's return type.
>     public abstract java.lang.Object insertOverTime(@org.jetbrains.annotations.NotNull()
>                                      ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:23:
> error: Not sure how to handle delete method's return type. Currently
> the supported return types are void, int or Int.
>     public abstract java.lang.Object deleteOverTime(@org.jetbrains.annotations.NotNull()
>                                      ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:25:
> error: Type of the parameter must be a class annotated with @Entity or
> a collection/array of it.
>     kotlin.coroutines.Continuation<? super java.lang.Integer> p1);
>                                                               ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:19:
> error: Type of the parameter must be a class annotated with @Entity or
> a collection/array of it.
>     kotlin.coroutines.Continuation<? super java.lang.Integer> p1);
>                                                               ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDAO.java:17:
> error: Not sure how to handle update method's return type. Currently
> the supported return types are void, int or Int.
>     public abstract java.lang.Object updateOverTime(@org.jetbrains.annotations.NotNull()
>                                      ^D:\TryOuts\OT_Tracker\app\build\tmp\kapt3\stubs\debug\net\androidtries\overtimetracker\db\OtTrackerDB.java:8:
> warning: Schema export directory is not provided to the annotation
> processor so we cannot export the schema. You can either provide
> `room.schemaLocation` annotation processor argument OR set
> exportSchema to false. public abstract class OtTrackerDB extends
> androidx.room.RoomDatabase {
>                 ^[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not
> incremental: androidx.room.RoomProcessor (DYNAMIC).

0 个答案:

没有答案
相关问题