【发布时间】:2021-11-25 00:34:23
【问题描述】:
我正在尝试使用 Android Room 2.3.0,但目前出现以下编译错误:
项目道:
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);
反道:
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
标签: android kotlin android-room