错误: Type of the parameter must be a class annotated with @Entity or a collection/array of it.

The specific error is as follows:

 错误: Type of the parameter must be a class annotated with @Entity or a collection/array of it.
    kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

 错误: Not sure how to handle insert method's return type.
    public abstract java.lang.Object insertAll(@org.jetbrains.annotations.NotNull()

After updating the Kotlin version, I used the module of the Android Jetpack Room library to compile an error. After some searching, I did not get the correct solution. After comparing the kotlin source file and the compiled java file, I found that it was a function defined in the Dao class of Room. Adding suspend causes the compiled function to have one more parameter:

@org.jetbrains.annotations.Nullable()
@androidx.room.Insert(onConflict = androidx.room.OnConflictStrategy.REPLACE)
public abstract java.lang.Object insertAll(@org.jetbrains.annotations.NotNull()
java.util.List<ButtonEntity> list, @org.jetbrains.annotations.NotNull()
kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

This is @org.jetbrains.annotations.NotNull() kotlin.coroutines.Continuation<? super kotlin.Unit> continuation) Type of the parameter must be a class annotated with @Entity or a collection/array of it. error when compiling.

The specific reason has not been investigated for the time being. The temporary solution is to remove the suspend of the function in the Dao class. I hereby record it. I will study the ins and outs of this problem later when I have time.

Update on August 09, 2022:

Friends who encounter this problem can follow Lantian Laoli and DukerDev in the comments to update Room to the corresponding version to solve this problem. Thank you for your enthusiastic reply!

 

Guess you like

Origin blog.csdn.net/xiangang12202/article/details/122526590