只是留下我的答案以防万一。我遇到了同样的问题,上面的答案都没有奏效。唯一有效的是将 a 更改data class
为 a class
。我邀请任何人尝试相同的代码并解释为什么它成功了:
前
@Entity
data class ImgurGalleryPost (
@NotNull @PrimaryKey
var id: String,
var title: String?,
var description: String?,
var datetime: Int?,
var cover: String?,
var coverWidth: Int?,
var coverHeight: Int?,
var accountUrl: String?,
var accountId: Int?,
var privacy: String?,
var layout: String?,
var views: Int?,
var link: String?,
var ups: Int?,
var downs: Int?,
var points: Int?,
var score: Int?,
var isAlbum: Boolean?,
var vote: Boolean?,
var favorite: Boolean?,
var nsfw: Boolean?,
var section: String?,
var commentCount: Int?,
var favoriteCount: Int?,
var topic: String?,
var topicId: Int?,
var imagesCount: Int?,
var inGallery: Boolean?,
var isAd: Boolean?,
@NotNull @Ignore
var tags: List<ImgurGalleryTag>,
var inMostViral: Boolean?,
@NotNull @Ignore
var images: List<ImgurGalleryImage>
)
后
@Entity
class ImgurGalleryPost (
@NotNull @PrimaryKey
var id: String,
var title: String?,
var description: String?,
var datetime: Int?,
var cover: String?,
var coverWidth: Int?,
var coverHeight: Int?,
var accountUrl: String?,
var accountId: Int?,
var privacy: String?,
var layout: String?,
var views: Int?,
var link: String?,
var ups: Int?,
var downs: Int?,
var points: Int?,
var score: Int?,
var isAlbum: Boolean?,
var vote: Boolean?,
var favorite: Boolean?,
var nsfw: Boolean?,
var section: String?,
var commentCount: Int?,
var favoriteCount: Int?,
var topic: String?,
var topicId: Int?,
var imagesCount: Int?,
var inGallery: Boolean?,
var isAd: Boolean?,
@NotNull @Ignore
var tags: List<ImgurGalleryTag>,
var inMostViral: Boolean?,
@NotNull @Ignore
var images:
List<ImgurGalleryImage>
)
这真的很奇怪,但我怀疑这是一个 Android Studio 缓存问题,因为将其更改回data class
会导致错误再次出现。似乎这是集合字段的某种问题。我检查了生成的类中的构造函数,它看起来很好,即使构造函数生成正确,我也不知道为什么构建失败:
public ImgurGalleryPost(@org.jetbrains.annotations.NotNull()
java.lang.String id, @org.jetbrains.annotations.Nullable()
java.lang.String title, @org.jetbrains.annotations.Nullable()
java.lang.String description, @org.jetbrains.annotations.Nullable()
java.lang.Integer datetime, @org.jetbrains.annotations.Nullable()
java.lang.String cover, @org.jetbrains.annotations.Nullable()
java.lang.Integer coverWidth, @org.jetbrains.annotations.Nullable()
java.lang.Integer coverHeight, @org.jetbrains.annotations.Nullable()
java.lang.String accountUrl, @org.jetbrains.annotations.Nullable()
java.lang.Integer accountId, @org.jetbrains.annotations.Nullable()
java.lang.String privacy, @org.jetbrains.annotations.Nullable()
java.lang.String layout, @org.jetbrains.annotations.Nullable()
java.lang.Integer views, @org.jetbrains.annotations.Nullable()
java.lang.String link, @org.jetbrains.annotations.Nullable()
java.lang.Integer ups, @org.jetbrains.annotations.Nullable()
java.lang.Integer downs, @org.jetbrains.annotations.Nullable()
java.lang.Integer points, @org.jetbrains.annotations.Nullable()
java.lang.Integer score, @org.jetbrains.annotations.Nullable()
java.lang.Boolean isAlbum, @org.jetbrains.annotations.Nullable()
java.lang.Boolean vote, @org.jetbrains.annotations.Nullable()
java.lang.Boolean favorite, @org.jetbrains.annotations.Nullable()
java.lang.Boolean nsfw, @org.jetbrains.annotations.Nullable()
java.lang.String section, @org.jetbrains.annotations.Nullable()
java.lang.Integer commentCount, @org.jetbrains.annotations.Nullable()
java.lang.Integer favoriteCount, @org.jetbrains.annotations.Nullable()
java.lang.String topic, @org.jetbrains.annotations.Nullable()
java.lang.Integer topicId, @org.jetbrains.annotations.Nullable()
java.lang.Integer imagesCount, @org.jetbrains.annotations.Nullable()
java.lang.Boolean inGallery, @org.jetbrains.annotations.Nullable()
java.lang.Boolean isAd, @org.jetbrains.annotations.NotNull()
java.util.List<com.kimboo.core.model.ImgurGalleryTag> tags, @org.jetbrains.annotations.Nullable()
java.lang.Boolean inMostViral, @org.jetbrains.annotations.NotNull()
java.util.List<com.kimboo.core.model.ImgurGalleryImage> images) {
super();
}
如果有人可以找到解决此问题的方法,而无需从更改为data class
,class
请随时在下面发表评论。