gpt4 book ai didi

android - 此方法仅在托管模式下可用

转载 作者:行者123 更新时间:2023-11-29 15:49:07 25 4
gpt4 key购买 nike

我正在开发一个集成了 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 */

我希望这个问题很详细。

提前致谢:)

最佳答案

发生这种情况是因为您提供给 findProductIntoChildrenByEntityId 方法的 RealmList 是一个独立的方法,也就是说,不由 Realm 管理。独立的 RealmList 只存在于内存中(而不是存在于 Realm 中),这意味着无法对其进行查询。

关于android - 此方法仅在托管模式下可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31429239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com