API 27空对象引用

时间:2018-08-07 09:50:26

标签: android

此代码在api 23上有效,但在api 27中无效。它向我显示此消息:

public class AdapterMenuList extends BaseAdapter {

    private Activity activity;

    public AdapterMenuList(Activity act) {
        this.activity = act;
    }

    public int getCount() {
        return ActivityMenuList.Menu_ID.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.lsv_item_menu_list, null);
            holder = new ViewHolder();

            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }

        holder.nameProduct = convertView.findViewById(R.id.nameProduct);
        holder.price50Text = convertView.findViewById(R.id.price50Text);
        holder.price100Text = convertView.findViewById(R.id.price100Text);
        holder.imgThumb = convertView.findViewById(R.id.imgThumb);

        holder.nameProduct.setText(ActivityMenuList.Menu_name.get(position));
        if(ActivityMenuList.Category_ID == 1 ){
            holder.price50Text.setText("Pret 50 Tb: "+ActivityMenuList.Menu_price50.get(position)+" "+ActivityMenuList.Currency);
            holder.price100Text.setText("Pret 100 Tb: "+ActivityMenuList.Menu_price100.get(position)+" "+ActivityMenuList.Currency);
        }else{
            holder.price50Text.setText("Pret: "+ActivityMenuList.Menu_price50.get(position)+" "+ActivityMenuList.Currency);
            holder.price100Text.setVisibility(View.GONE);
        }
        Picasso.with(activity).load(Config.ADMIN_PANEL_URL+"/"+ActivityMenuList.Menu_image.get(position)).placeholder(R.drawable.loading).into(holder.imgThumb);

        return convertView;
    }

    static class ViewHolder {
        TextView nameProduct, price50Text, price100Text;
        ImageView imgThumb;
    }


}

有人可以帮忙吗?

我无法解决这个问题。我现在被困了一个多星期。

代码是:

{{1}}

0 个答案:

没有答案