RealmObject with RealmList<String>

Im trying to create a RealmList field for one of my RealmObjects in Java but i get an error in realm logs saying that “sync does not support collections of nullable primitives unless using the mixed type”. All the documentations show that that is doable.

public class UserModel extends RealmObject{
    String _id;
    RealmList<String> contacts;

What am i doing wrong?

1 Like

Hi @Ibrahim_Abouelseoud, welcome to the community forum.

Did you find a solution for this?

What does your backend Realm schema look like?

1 Like

****** FINALLY FIXED ******
There are multiple steps you have to do and multiple rules you have to follow in order to make this work. First I will cover the rules in order to correctly set up your Java object model, then I will guide you through the steps to create a schema from them.


  1. Every RealmList of a primitive type (e.g. String, Integer, Boolean, Double …) must be @Required in the Java Class (e.g. @Required public RealmList{String} comments; Use < and > instead of the brackets obviously, it just doesnt display here so i had to replace it by brackets) (The annotations have to be imported from
import io.realm.annotations.PrimaryKey;
import io.realm.annotations.Required;

2. Every other RealmList of for example another type you define in your app (e.g. RealmList{Article} where Article is another one of your Realm Object Classes) you can not put @Required
3. The @PrimaryKey attribute has to be @Required, for example @PrimaryKey @Required public ObjectId _id;
4. If your partition key is a synthetic one like ‘_partition’, it should not be one of the attributes of your Realm model class (just leave it away. Realm automatically adds _partition to your schema then!)
5. Don’t use @NonNull for anything

Steps to create a schema from your Java classes (also called the Realm Object Model):
(this guide is for Android Studio)

  1. Terminate the app within Android Studio if it is currently running. This closes all open Realms or Syncs and avoids automatically up- or downloading anything prematurely.
  2. Delete all the schemas from any collection (form the Realm UI)for that you want to create a schema now (if there are aready some, e.g. from further testing). Many changes like adding @Required to an attribute do otherwise not work! You do this from the Realm UI, go to Data Access → Schema in the Menu on the left and click the three dots on your Database name, then choose ‘Delete schemas from all collections’. Before that step it might be mandatory to Terminate sync and enable it again. Don’t forget to activate Development mode in the Device Sync section!
  3. Delete/wipe the local Realm files within Android Studio (if you are testing on emulator) or on your smartphone (if you’re testing the app on your smartphone directly). For the first step, go to “Device File Explorer” on the FAR RIGHT bottom left corner of Android Studio.
    Navigate to data/user/0/com../files and delete (click on it and press delete-key on your keyboard) the whole mongodb-realm folder (if you want to keep some stuff, you can also go into that folder and only delete all the realm files from the partition you want to edit. It’s way simpler to just delete the whole folder.)
  4. Make sure you have Development mode for device sync on. Make sure your IP has access to the Realm App! A personal IP changes every few days so you have to always update this! Super important!!! Check this in the Realm UI under App settings → IP Access List (the tab on the top of the page) and delete the current entry and press “add ip address” and click current ip address. you can also use the “allow access from anywhere” option but this may be unsafe in early stages of development when you not have your permissions set up securely.
  5. Now start the application from Android Studio. I think it’s important to log in to the realm, anonymous auth and email password auth both worked for me independently. Maybe it is mandatory to actually open a synced realm. Either way, you don’t have to do much more. Just run the application until you are logged in. You can terminate the app or let it run, it doesnt matter.
  6. Last step: Go to Realm UI and go to Device Sync, from there disable development mode and then choose “view schema”. Now it’s completely done and you should see your schema.
1 Like