2016-01-20 49 views
1

我想刪除其中一個存儲的realm物件。但我不斷收到錯誤。刪除存儲的實物之一android

val realm = Realm.getInstance(this) 
     val allUsers = realm.where(User::class.java).findAll() 
     val deletedDependent = realm.where(User::class.java).equalTo("id",deleteDependentData.dependentUUID).findFirst() 

     try { 
      realm.beginTransaction() 
      deletedDependent.removeFromRealm() 
      realm.commitTransaction() 
     } catch (e: RealmException) { 
      info("Error deleting realm object=>${e.message}") 
      e.printStackTrace() 
     } 

日誌說,Could not find class 'io.realm.rx.RealmObservableFactory$1', referenced from method io.realm.rx.RealmObservableFactory.from

如果我用removeLast,它抱怨是不支持刪除。有人可以幫我解決這個問題嗎?

回答

0

我克服了這個問題,將RxAndroid添加到我的項目依賴項中。

編譯 'io.reactivex:rxandroid:0.25.0'

+0

如果您不使用Rx,則不必添加RxAndroid,您只需創建一個虛擬對象,如下所示:https://realm.io/docs/java/latest/#jackson-databind – EpicPandaForce

0
@RealmClass 
public abstract class RealmObject implements RealmModel { 

    /** 
    * Deletes the object from the Realm it is currently associated to. 
    * <p> 
    * After this method is called the object will be invalid and any operation (read or write) performed on it will 
    * fail with an IllegalStateException. 
    * 
    * @throws IllegalStateException if the corresponding Realm is closed or in an incorrect thread. 
    * @see #isValid() 
    */ 
    public final void deleteFromRealm() { 
     deleteFromRealm(this); 
    } 
...... 

} 

這可能幫助你。如果答案是沒有用的話,請回復。