我正试图使用Android Room 2.3.0,但目前我遇到了以下编译错误:
ProjectDao:
error: Not sure how to handle query method's return type (java.lang.Object). DELETE query methods must either return void or int (the number of deleted rows).
public abstract java.lang.Object deleteAllProjects(@org.jetbrains.annotations.NotNull()
error: Query method parameters should either be a type that can be converted into a database column or a List / Array that contains such type. You can consider adding a Type Adapter for this.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
error: Unused parameter: continuation
public abstract java.lang.Object deleteAllProjects(@org.jetbrains.annotations.NotNull()
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> continuation);
error: Not sure how to handle insert method's return type.
public abstract java.lang.Object insertProject(@org.jetbrains.annotations.NotNull()
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 deleteProject(@org.jetbrains.annotations.NotNull()
error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);
计数器DAO:
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)
然而,我的ProjectDao.kt文件包含以下内容:
@Dao
interface ProjectDao {
@Query("SELECT * FROM table_projects")
fun getAll(): List<Project>
@Insert
suspend fun insertProject(project: Project): Long
@Insert
fun insertProjects(projects: List<Project>)
@Delete
suspend fun deleteProject(project: Project)
@Query("DELETE FROM table_projects")
suspend fun deleteAllProjects()
@Transaction
@Query("SELECT * FROM table_projects")
fun getAllProjectsWithCounters(): List<ProjectWithCounters>
@Transaction
@Query("SELECT * FROM table_projects WHERE id_project=:projectID")
fun getProjectWithCounters(projectID: Long): ProjectWithCounters
}
我之前没有遇到过这种问题,突然间出现了这些错误,我不知道是什么原因导致的。
谢谢!
room-ktx
?请在你的build.gradle
文件中包含它。 - ianhanniballake