Ill*_*lyk 2 java android parse-platform
我在我的项目中使用 Parse.com。我想创建自己的实体类 extends Parse Object 但我有一个 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");
}Run Code Online (Sandbox Code Playgroud)
注册一个子类
public class ParseApp extends Application {
@Override
public void onCreate() {
ParseObject.registerSubclass(Recipe.class);
Parse.initialize(this, "XXXXXX", "XXXXXXX");
}
}Run Code Online (Sandbox Code Playgroud)
异常发生在适配器的 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();
}
Run Code Online (Sandbox Code Playgroud)
}
比较一下:
@ParseClassName("Recipe")
Run Code Online (Sandbox Code Playgroud)
对此:
ParseQuery query = new ParseQuery("OwnRecipeBook");
Run Code Online (Sandbox Code Playgroud)
存在类型不匹配。尝试使用相同的名称。这些类型对您来说可能看起来很明显相同,但 Parse 需要准确、明确地知道您要做什么。
| 归档时间: |
|
| 查看次数: |
2402 次 |
| 最近记录: |