android - 构建房间期间出现 StackOverflowError

标签 android database kotlin android-room

我正在尝试使用空间并写下以下内容:

@Entity(foreignKeys = arrayOf(ForeignKey(entity = Category::class, 
parentColumns = arrayOf("id"), childColumns = arrayOf("parentId"))))
data class Category (
    val type: Byte,

    val name: String,

    val description: String,

    var parentId: Long? = null,

    var remoteId: Long? = null,

    @PrimaryKey(autoGenerate = true)
    val id: Long = 0L,

    @Relation(parentColumn = "id", entityColumn = "parentId")
    var subcategories: List<Category>? = null
)

但是我得到了这个:

Error:Execution failed for task ':app:kaptDebugKotlin'.
> Internal compiler error. See log for more details

以及更多详细信息:

 java.lang.IllegalStateException: failed to analyze: 
 java.lang.StackOverflowError
 at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)

也许有人面临这个问题(因为没有子类别字段一切都很好)。

谢谢!

最佳答案

引用the documentation for @Relation :

Note that @Relation annotation can be used only in Pojo classes, an Entity class cannot have relations.

理想情况下,您会得到比 StackOverflowError 更好的构建错误,但您应该得到某种形式的构建错误。

关于android - 构建房间期间出现 StackOverflowError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50317853/

相关文章:

java - 如何从url中获取特定数据?

java - 应用无法在我的真实设备上加载插页式广告

android - 如何快速构建Android应用程序?

database - Golang mgo 查找

database - Windows 上的 Oracle 12c 安装 - 安装程序验证失败

android - Kotlin - 从键值对的 HashMap 中检索数据

android - Kotlin-在随机列表中获取新的项目索引

Android应用程序字体大小根据设置中定义的字体大小而变化

c# - 动态选择数据库

java - 如何在android中使用Canvas在线尖上画一个圆