我有薩姆問題,更新的境界境界新變化?
這是我的類
public class Cliente extends RealmObject {
@PrimaryKey
private long id;
@Required
private String nombre;
private String apellido;
private String imagen;
private boolean habilitado;
private RealmList<Obra> obras;
而且有這樣的代碼只能做插入
Realm realm = Realm.getDefaultInstance();
realm.beginTransaction();
Cliente cliente = realm.createObject(Cliente.class);
cliente.setId(1);
cliente.setNombre("Desconocido");
cliente.setApellido("-");
cliente.setHabilitado(true);
realm.copyFromRealm(cliente);
realm.commitTransaction();
realm.close();
確定y的問題,但以往任何時候都以這種方式工作與realm and android
Caused by: io.realm.exceptions.RealmException: 'Cliente' has a primary key, use 'createObject(Class<E>, Object)' instead.
at io.realm.Realm.createObjectInternal(Realm.java:820)
at io.realm.Realm.createObject(Realm.java:801)
at app.obraresuelta.model.Cliente.insertUsuarioDefault(Cliente.java:38)
at app.obraresuelta.PrincipalActivity.onCreate(PrincipalActivity.java:31)
at android.app.Activity.performCreate(Activity.java:6289)
ty for u answer only change添加'Cliente cliente = realm.createObject(Cliente.class,1);' – marlonpya