Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

3.6K
Visualizações
Android Room Kotlin arroja un error de consulta de eliminación

Estoy tratando de usar Android Room 2.3.0 y actualmente recibo los siguientes errores de compilación:

ProyectoDao:

 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);

ContraDao:

 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)

Sin embargo, mi archivo ProjectDao.kt tiene lo siguiente:

 @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 }

No he tenido ningún problema con esto anteriormente, y de repente recibo estos errores y no tengo idea de qué podría estar causándolos.

¡Gracias!

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Establecer la versión de Kotlin es 1.5.21 o 1.5.31
Kotlin 1.6.0 no puede usar suspend en ROOM @QUERY
Elija una de las siguientes soluciones

  1. abre tu raíz build.gradle y agrega esto
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21'
  2. abra su módulo build.gradle y cambie la habitación-versión uno de 2.4.0-alpha03 hasta 2.4.0-beta01
    def roomVersion = "2.4.0-alpha03"
over 4 years ago · Santiago Trujillo Relatório

0

Resolví este problema de la siguiente manera

Configuré la versión de Kotlin en 1.6.10 que Room en 2.4.2

over 4 years ago · Santiago Trujillo Relatório

0

Con la anotación @Delete , debe definir un tipo de datos de retorno:

Los métodos de consulta DELETE deben devolver void o int (el número de filas eliminadas).

Así que esto debería ser más bien:

 @Delete suspend fun deleteProject(project: Project): Integer

Esto devolvería 1 en caso de éxito y 0 cuando el project no existiera en la base de datos.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda