0

I'm trying to save the data class i got from json to room database and suddenly get errors like this while building the app.

Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).

NewsResponse model object

data class NewsResponse(
    val copyright: String,
    val response: Response,
    val status: String
)

Response object

data class Response(
    val docs: List<Docs>
)

Docs object(this is the data class i want to save)

@Entity(
    tableName = "docs"
)
data class Docs(
    @PrimaryKey(autoGenerate = true)
    var id: Int? = null,
    val _id: String,
    val `abstract`: String,
    @Embedded
    val byline: Byline,
    val document_type: String,
    @Embedded
    val multimedia: Multimedia,
    @Embedded
    val headline: Headline,
    val lead_paragraph: String,
    val news_desk: String,
    val pub_date: String,
    val section_name: String,
    val snippet: String,
    val source: String,
    val subsection_name: String,
    val type_of_material: String,
    val uri: String,
    val web_url: String,
    val word_count: Int
)

Byline object

@Entity
data class Byline(
    val original: String
)

Multimedia object

@Entity
data class Multimedia(
    val url: String
)

Headline object

@Entity
data class Headline(
    val main: String
)

Any ideas how to solve this?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
  • Does this answer your question? [Room Persistence: Error:Entities and Pojos must have a usable public constructor](https://stackoverflow.com/questions/44485631/room-persistence-errorentities-and-pojos-must-have-a-usable-public-constructor) – mightyWOZ Jul 19 '21 at 15:59
  • I already tried the solution that are given from the thread, but still doesn't solve my problem:( – Adrian Prawira Jul 19 '21 at 16:06

0 Answers0