Room cannot pick a constructor since multiple constructors are suitable error

Gogi Bobina picture Gogi Bobina · Jun 19, 2017 · Viewed 15k times · Source

I try to implement persistent library in my android kotlin project, but catch this error on compile time:

error: Room cannot pick a constructor since multiple constructors are suitable. Try to annotate unwanted constructors with @Ignore.

Error code:

@Entity
data class Site(
        var name: String = "",
        var url: String = "",
        @PrimaryKey(autoGenerate = true) var id: Long = 0)

Answer

Gogi Bobina picture Gogi Bobina · Jun 19, 2017

I had this error because Kotlin apparently generates multiple Java constructors for a single Kotlin constructor with default argument values. Working code see next:

@Entity
data class Site(
        var name: String,
        var url: String,
        @PrimaryKey(autoGenerate = true) var id: Long)