我在我的项目中使用Parse.com。我想创建自己的实体类扩展Parse Object但我有一个java.lang.ClassCastException:com.parse.ParseObject无法强制转换为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();
}
}
答案 0 :(得分:4)
比较一下:
@ParseClassName("Recipe")
对此:
ParseQuery query = new ParseQuery("OwnRecipeBook");
存在类型不匹配。尝试使用相同的名称。这些类型可能看起来与你完全相同,但是Parse需要准确,明确地知道你想要做什么。