Room Persistence: Error:Entities and Pojos must have a usable public constructor

前端 未结 24 1806
长发绾君心
长发绾君心 2020-12-01 09:05

I\'m converting a project to Kotlin and I\'m trying to make my model (which is also my entity) a data class I intend to use Moshi to convert the JSON responses from the API<

24条回答
  •  臣服心动
    2020-12-01 09:30

    https://issuetracker.google.com/issues/62851733

    i found this is @Relation's projection bug! not Kotlin language problem. based google GithubBrowserSample java also happend error, but different error message.

    below is my kotlin code:

    data class UserWithCommunities(
            @Embedded
            var user: User = User(0, null),
    
            @Relation(parentColumn = "id",
                    entityColumn = "users_id",
                    entity = CommunityUsers::class,
                    projection = arrayOf("communities_id")) // delete this line.
            var communityIds: List = emptyList()
    )
    

    right:

    data class UserWithCommunities(
            @Embedded
            var user: User = User(0, null),
    
            @Relation(parentColumn = "id",
                    entityColumn = "users_id",
                    entity = CommunityUsers::class)
            var communityList: List = emptyList()
    )
    

提交回复
热议问题