无法将类别转换为ParseObject [英] Class cannot be cast to ParseObject

查看:85
本文介绍了无法将类别转换为ParseObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用Parse.com.我想创建自己的实体类扩展Parse Object,但是我有一个java.lang.ClassCastException:com.parse.ParseObject无法转换为com.james.strongpeopleapp.Recipe

I am using Parse.com in my project. I want to create my own entity class extends Parse Object but I have a java.lang.ClassCastException: com.parse.ParseObject cannot be cast to com.james.strongpeopleapp.Recipe

@ParseClassName("Recipe")
public class Recipe extends ParseObject {

    public Recipe() {
    }

    public String getRecipeName(){
        return getString("RecipeName");
    }

注册子类

public class ParseApp extends Application {

    @Override
    public void onCreate() {

        ParseObject.registerSubclass(Recipe.class);
        Parse.initialize(this, "XXXXXX", "XXXXXXX");

    }
}

适配器的getItemView()中发生异常

Exception take place in getItemView() in adapter

 public class MainParseAdapter extends ParseQueryAdapter<Recipe> {

private LayoutInflater layoutInflater;

public MainParseAdapter(Context context) {

    super(context, new QueryFactory<Recipe>() {
        @Override
        public ParseQuery<Recipe> create() {
            ParseQuery query = new ParseQuery("OwnRecipeBook");
            return query;
        }
    });

    layoutInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getItemView(Recipe recipe, View v, ViewGroup parent) {

    if(v == null){
        v = layoutInflater.inflate(R.layout.recipe_item, parent, false);
    }
    super.getItemView(recipe, v, parent);

    TextView mName = (TextView) v.findViewById(R.id.recipe_tw);
    mName.setText(recipe.getRecipeName());

    ParseImageView mImage = (ParseImageView) v.findViewById(R.id.recipe_imageView);
    mImage.setParseFile(recipe.getRecipeImage());
    mImage.loadInBackground();

    return v;
}

public String getItemIdFromTable(int position){
    return getItem(position).getObjectId();
}

}

推荐答案

比较一下:

@ParseClassName("Recipe")

对此:

ParseQuery query = new ParseQuery("OwnRecipeBook");

类型不匹配.尝试使用相同的名称.这些类型可能看起来与您完全相同,但是Parse必须准确,准确地知道您要执行的操作.

There's a type mismatch. Try to use the same name. Those types may look obviously identical to you, but Parse needs to know precisely, unambiguously what you're trying to do.

这篇关于无法将类别转换为ParseObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆