簡體   English   中英

無法將類別轉換為ParseObject

[英]Class cannot be cast to ParseObject

我在我的項目中使用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();
}

}

比較一下:

@ParseClassName("Recipe")

對此:

ParseQuery query = new ParseQuery("OwnRecipeBook");

類型不匹配。 嘗試使用相同的名稱。 這些類型可能看起來與您完全相同,但是Parse必須准確,准確地知道您要執行的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM