gpt4 book ai didi

java - 类不能转换为 ParseObject

转载 作者:搜寻专家 更新时间:2023-11-01 07:54:30 26 4
gpt4 key购买 nike

我在我的项目中使用 Parse.com。我想创建自己的实体类扩展 Parse 对象,但我有一个 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()发生异常

 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 需要准确、明确地知道您要做什么。

关于java - 类不能转换为 ParseObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30055743/

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