androidconstructorkotlinandroid-roomandroid-components

Room cannot pick a constructor since multiple constructors are suitable error


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)

Solution

  • 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)