When using version 4.3.3
of REALM
for Android development I get the following error:
Error: Field "groupName" with type "pizware.evaluapp.Models.Group" can not be @Required or @NotNull.
but I do not use any of those labels for any field. Does anyone know what is going on?
When you use Kotlin, then Realm checks against nullability on your field.
For example,
class Blah: RealmObject() {
var group: Group? = null
}
Then group
doesn't get implicit @Required
annotation.
But if you do
class Blah: RealmObject() {
var group: Group = Group()
}
This won't work, because Realm cannot guarantee non-nullability for a singular link. So it'll throw the error you're getting.
If you want to ignore this because for example you are making a backing field that avoids null value return
get() = group ?: Group()
Then you can use (since 4.1.0):
kapt {
arguments {
arg("realm.ignoreKotlinNullability", true)
}
}
In which case Realm won't try to handle your nullability implicitly (and map the Kotlin nullability to the field's @Required
). But you should use this only if you actually know what you're doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With