当前位置: 首页 > 知识库问答 >
问题:

java.lang.ClassCastException:不能将Com.Parse.ParseObject强制转换为

姚树
2023-03-14

这是我的RestaurantAdapter

public class RestaurantAdapter extends ParseQueryAdapter<Restaurant> {
    //top line is 17
    private AlphaAnimation buttonClick;
    public RestaurantAdapter(Context context, final String filter_edit, final String filter_city, final String filter_region,0 final int filter_sort) {
       super(context, new ParseQueryAdapter.QueryFactory<Restaurant>() {
           public ParseQuery<Restaurant> create() {
               // Here we can configure a ParseQuery to display
               // only top-rated meals.
               ParseQuery query = new ParseQuery("Restaurant");
               query.whereContains("city", filter_city);       
    if(!filter_region.equals("*Hepsi*")&&!filter_region.equals("*All*"))
                   query.whereContains("region",filter_region);
               if(filter_edit.equals("nothing")){
               }else{
                   query.whereStartsWith("restaurant", filter_edit);
               }
               switch(filter_sort){
                   case 0:
                       query.orderByAscending("averagePrice");
                       break;
                   case 1:
                       query.orderByDescending("averagePrice");
                       break;
                   case 2:
                       query.orderByAscending("restaurant");
                       break;
                   case 3:
                       query.orderByDescending("averagePoint");
                       break;
                   default:
                       query.orderByAscending("restaurant");
                       break;
               }
               return query;
           }
       });
    }
    @Override
    public View getItemView(Restaurant restaurant, View v, ViewGroup parent) {
        //buttonClick = new AlphaAnimation(1F, 0.8F);
        if (v == null) {
            v = View.inflate(getContext(), R.layout.restaurant_list_item, null);
        }
        super.getItemView(restaurant, v, parent);
        final String str_call = restaurant.getPhone();
        TextView locationTextView = (TextView) v.findViewById(R.id.restaurant_location);
        String str_location= restaurant.getRegion()+", "+restaurant.getCity();
        locationTextView.setText(str_location);
        TextView nameTextView = (TextView) v.findViewById(R.id.restaurant_name);
        nameTextView.setText(restaurant.getName());
        TextView pointTextView = (TextView) v.findViewById(R.id.restaurant_point);
        String str_point = String.valueOf(restaurant.getAveragePoint());
        pointTextView.setText(str_point);
        TextView priceTextView = (TextView) v.findViewById(R.id.restaurant_averageprice);
        String str_price = String.valueOf(restaurant.getAveragePrice())+" TL";
        priceTextView.setText(str_price);
        ImageView callImage = (ImageView) v.findViewById(R.id.restaurant_call);
        callImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View w) {
                // w.startAnimation(buttonClick);
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:"+str_call));
                w.getContext().startActivity(intent);
            }
        });
        TextView mapText = (TextView) v.findViewById(R.id.restaurant_map);
        mapText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View w) {
                //w.startAnimation(buttonClick);
            }
        });
        return v;
    }
}

共有1个答案

邓开济
2023-03-14

你得检查两件事

>

  • 确保您的子类具有public default(即零参数)构造函数。不能修改此构造函数中的任何ParseObject字段。而且

    在调用Parse.Initialize()之前,在应用程序构造函数中调用ParseObject.RegisterSubclass(YourClass.Class)

  •  类似资料: