我正在尝试使用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);
反刀:
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
}
我以前没有遇到过任何问题,突然之间我得到了这些错误,我不知道是什么导致了它们。
谢谢!
7条答案
按热度按时间6ljaweal1#
更新房间版本:2.4.3Kotlin:1.7.20
这解决了问题。
nzk0hqpo2#
设置Kotlin版本为1.5.21或1.5.31
Kotlin1.6.0无法在ROOM
@QUERY
中使用suspend
选择以下解决方案之一
1.打开你的root build.gradle并添加这个
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21'
1.打开你的模块build.gradle并将2.4.0-alpha 03中的room-version更改为2.4.0-beta 01
def roomVersion = "2.4.0-alpha03"
n6lpvg4x3#
我解决这个问题的方法如下
我把Kotlin版本设置为1.6.10,把Room设置为2.4.2
6za6bjd04#
使用
@Delete
注解,你必须定义一个返回数据类型:DELETE查询方法必须返回void或int(删除的行数)。
所以这应该是:
这将在成功时返回
1
,并在project
不存在于数据库中时返回0
。7uzetpgm5#
检查Answer应该对您有帮助。
yh2wf1be6#
作为更新,您现在可以使用
Kotlin 1.7.10
将您的房间版本更改为Room 2.4.3
,所有问题都将得到解决s3fp2yjn7#
在尝试其他更有效的方法之前,您可以尝试删除
suspend
。我也遇到过类似的问题。并建议由高级尝试删除它和该项目进行顺利,直到日期