【问题标题】:How to add an array of self-objects to the room database如何将一组自对象添加到房间数据库
【发布时间】:2020-07-08 12:33:13
【问题描述】:

我有一些数据类,其中包括他自己作为列表。 Android studio 显示下一个错误:

    ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version 4.7.1ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime version 4.7.1C:\..\EventType.java:14: error: Cannot figure out how to save this field into database. You can consider adding a type converter for it.
    private final java.util.List<...EventType> children = null;
Task :app:kaptDebugKotlin FAILED
                                                                                 ^
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

数据类是

@Entity(tableName = "eventType")
data class EventType(
    @PrimaryKey val id: Int,
    val name: String,
    val children: List<EventType>,
    val minAge: Int = 0
)

编辑:谢谢,下一条评论很有用 You have to use teh Room data type converter , look stackoverflow.com/questions/53085704/room-typeconverter – eurosecom

【问题讨论】:

标签: android android-studio kotlin android-room androidx


【解决方案1】:

在您的build.graddle 文件中更改:

import(Room.compiler)

为:

kapt(Room.compiler)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 1970-01-01
    • 2018-03-16
    相关资源
    最近更新 更多