我正在开发一个集成了Realm的Android应用程序,当我尝试使用查询进行搜索时遇到问题。我尝试将产品按“id”搜索到参数传递的产品列表中。这种方法很完美但突然间我得到了下一个例外:
Process: com.singularfactory.ecommerceapp.ecommerceapp, PID: 9372
io.realm.exceptions.RealmException: This method is only available in managed mode
at io.realm.RealmList.where(RealmList.java:260)
at com.singularfactory.ecommerceapp.utility.UtilityDB.findProductIntoChildrenByEntityId(UtilityDB.java:176)
at com.singularfactory.ecommerceapp.fragment.ProductDetailFragment.setProductRealmToView(ProductDetailFragment.java:378)
at com.singularfactory.ecommerceapp.fragment.ProductDetailFragment.initializeEnvironment(ProductDetailFragment.java:119)
at com.singularfactory.ecommerceapp.fragment.ProductDetailFragment.onActivityCreated(ProductDetailFragment.java:96)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1797)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:979)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:490)
at com.singularfactory.ecommerceapp.fragment.ListsFragment.openProductDetailFragment(ListsFragment.java:256)
at com.singularfactory.ecommerceapp.fragment.ListsFragment$5.onClick(ListsFragment.java:193)
at com.singularfactory.ecommerceapp.adapter.ListsContentAdapter.onClick(ListsContentAdapter.java:78)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
我的代码:
/**
* Find a product into Children by entityId
* @param products
* @param entityId
* @return
*/
public static ProductRealm findProductIntoChildrenByEntityId(RealmList<ProductRealm> products, String entityId) {
ProductRealm product = null;
if(products != null) {
**product = products.where()** //The problem is here
.equalTo("entityId", entityId)
.findFirst();
}
return product;
}
我的模特:
@RealmClass
public class ProductRealm extends RealmObject implements Serializable {
private String catId; //Only one category per product. In generic case many category per product
private String entityId;
private String parentId;
private String typeId; //"simple" | "configurable"
private String sku;
private String canaryProduct;
private String premium;
private String brand;
private String dinitosQty;
private String name;
private String ean;
private String description;
private String shortDescription;
private String weight;
private String isSaleable;
private String imageUrl;
private String unit;
private String unitFresh;
private String childrenSelected;
private String manageStock;
private float price;
private float minWeight;
private float quantityWeight;
private int quantity;
private int stock;
private int typeOfAttribute; //0: Per units | 1: Per weight | 2: Both
private int typeOfChildrenSelected; //0: Per units | 2: Per weight | -1: Undefined
private boolean isIntoShoppingCart; //Flag to indicate if the product is into the Shopping Cart
private RealmList<AttributeRealm> attributeItems;
private RealmList<ProductRealm> children;
...
/* Getters & Setters */
我希望这个问题非常详细。
提前致谢:)