I am encountering the issue like stated in the title. I have the following entities:
@Entity
data class FichePrItem(
@PrimaryKey var id: String,
var observation: String?,
@Ignore var document: Documents,
@Embedded var action: Action,
var isSelected: Boolean = false
) {
var documentId = document.id
}
class Action(@SerializedName("libelleDisplay") val decision: String?)
@Entity
data class Documents(
@PrimaryKey var id: String,
var objet: String?,
@SerializedName("referenceArchive") var numeroEnrolement: String?,
@Ignore var ministere: Ministeres
) {
var ministereId: String = ministere.id
}
@Entity
data class Ministeres(
@PrimaryKey var id: String,
@SerializedName("code")
var sigle: String?
)
When building my project, i get the following gradle errors:
e: /Users/armelus/StudioProjects/opensi/FichePRSample/econseildb/build/tmp/kapt3/stubs/debug/co/opensi/econseildb/FichePrItem.java:7: error: 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).
public final class FichePrItem {
^
Tried the following constructors but they failed to match:
FichePrItem(java.lang.String,java.lang.String,co.opensi.econseildb.Documents,co.opensi.econseildb.Action,boolean) -> [param:id -> matched field:id, param:observation -> matched field:observation, param:document -> matched field:unmatched, param:action -> matched field:action, param:isSelected -> matched field:isSelected]
e: /Users/armelus/StudioProjects/opensi/FichePRSample/econseildb/build/tmp/kapt3/stubs/debug/co/opensi/econseildb/Documents.java:7: error: 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).
public final class Documents {
^
Tried the following constructors but they failed to match:
Documents(java.lang.String,java.lang.String,java.lang.String,co.opensi.econseildb.Ministeres) -> [param:id -> matched field:id, param:objet -> matched field:objet, param:numeroEnrolement -> matched field:numeroEnrolement, param:ministere -> matched field:unmatched]
When i comment @Ignore lines, the build finish successfully otherwise, it fails
implementation "androidx.room:room-runtime:2.1.0-alpha05"
kapt "androidx.room:room-compiler:2.1.0-alpha05"
Hi!
You have to move your @Ignore fields out of constructor and set default value for them. For example:
@Entity
data class FichePrItem(
@PrimaryKey var id: String,
var observation: String?,
@Embedded var action: Action,
var isSelected: Boolean = false
) {
@Ignore var document: Documents = Documents()
// or @Ignore var document: Documents? = null
var documentId = document.id
}
Hi!
You have to move your@Ignorefields out of constructor and set default value for them. For example:@Entity data class FichePrItem( @PrimaryKey var id: String, var observation: String?, @Embedded var action: Action, var isSelected: Boolean = false ) { @Ignore var document: Documents = Documents() // or @Ignore var document: Documents? = null var documentId = document.id }
Thanks, @borysmatveichuk,
Thank you for your answer, I tried it and it works well. But doing so does not really suit me because I would not like to be forced to assign a value by default.
Is there really no other way to settle this?
In fact when I use version 1.1.1 (without androidX), I see that I do not have this kind of error, is it an internal bug to the librairy under androidX?
Most helpful comment
Hi!
You have to move your
@Ignorefields out of constructor and set default value for them. For example: