Primary keys are immutable since Realm 2.0.0, which means you cannot modify them after the object has been created. So pass it at the time of object creation.
Useruser=realm.createObject(User.class,UUID.randomUUID().toString());user.setFirstName("Theo");user.setLastName("Larsen");
文章出处:https://stackoverflow.com/questions/41046279/user-has-a-primary-key-use-createobjectclasse-object-instead