简体   繁体   English

Kotlin上的Room Database有什么问题?

[英]What's wrong with Room Database on Kotlin?

I have a data class 我有一个数据班

@Entity(tableName = "type")
data class Type(
    @PrimaryKey(autoGenerate = true) var id: Int = 0,
    var type: Int = 0
)

When compiling project I receive message 编译项目时,我收到消息

Error:Room cannot pick a constructor since multiple constructors are suitable. 错误:房间无法选择一个构造函数,因为多个构造函数均适用。

But if I change data class to 但是如果我将数据类更改为

@Entity(tableName = "type")
data class Type(
    @PrimaryKey(autoGenerate = true) var id: Int = 0,
    var type: String = ""
)

or java class 或Java类

@Entity(tableName = "type")
public class Type {
    @PrimaryKey(autoGenerate = true)
    private int id;
    private int type;
    // getters and setters
}

it works fine. 它工作正常。 Is it Kotlin bug or something else? 是Kotlin错误还是其他?

I do not know why this occurs, but if you use id? 我不知道为什么会这样,但是如果您使用id? = 0 solves the problem, at least in the tests I did. = 0解决了这个问题,至少在我所做的测试中。

Android Studio Beta 7
ext.support_version = '26 .1.0 '
ext.kotlin_version = '1.1.51'
ext.anko_version = '0.10.1'
ext.archroom_version = '1.0.0-alpha9-1'

    @Entity(tableName = "type")
    data class Type(
            @PrimaryKey(autoGenerate = true) var id: Int? = 0,
            var type: Int = 0
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM