【发布时间】:2020-12-05 04:42:02
【问题描述】:
我有一个名为 Conversation 的 Room 数据库实体,我想 androidx.room.@Ignore messages 成员变量。但是,当我尝试运行该应用程序时,我收到此错误。
/db/entity/Conversation.java:10: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
public final class Conversation {
^
Tried the following constructors but they failed to match:
Conversation(int,java.util.List<com.example.app.db.entity.Message>) -> [param:id -> matched field:id, param:messages -> matched field:unmatched]/db/entity/Conversation.java:12: error: Cannot find setter for field.
private final int id = 0;
这是实体代码。
/**
* Entity used to model the conversation SQLite table in the database.
*/
@Entity(tableName = "conversation")
data class Conversation(
@PrimaryKey val id: Int,
@Ignore val messages: List<Message>
)
当我注释掉 @Ignore val messages... 行时,应用程序编译。
我已经尝试了 Room 数据库版本 2.2.5 和 2.3.0-alpha03 并且都出现了相同的错误。
【问题讨论】:
标签: android kotlin android-room android-jetpack