繁体   English   中英

java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMap无法强制转换为com.example

[英]java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.example

我试图使用BaseAdapter解析json。我正在尝试使用BaseAdapter在listview中显示值。 当我在BaseAdapter使用map时,我收到以下错误。

java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMap无法强制转换为com.example.prakash.pix91.get.Templates.pix上的com.example.prakash.pix91.get.Templates.pixjson.EffectList.get.Templates.multiple_array.MyContactAdapter2 .getView(MyContactAdapter2.java:76)

我在这做错了什么?

谢谢

MyContactAdapter2.java

    public class MyContactAdapter2 extends BaseAdapter {
    List<Map<String, List<EffectList>>> contactList;
    Context context;
    private LayoutInflater mInflater;

    public MyContactAdapter2(Context context, List<Map<String, List<EffectList>>> objects) {
        this.context = context;
        this.mInflater = LayoutInflater.from(context);
        contactList = objects;
    }


    @Override
    public int getCount() {
        Integer s = contactList.size();
        Log.d("Total count ", s.toString());
        return contactList.size();
    }


    @Override
    public Object getItem(int position) {

        return contactList.get(position);
    }


    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder1 vh1;
        if (convertView == null) {
            View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
            vh1 = ViewHolder1.create((RelativeLayout) view);
            view.setTag(vh1);
        } else {
            vh1 = (ViewHolder1) convertView.getTag();
        }


        EffectList item = (EffectList) getItem(position);


        //   vh.textViewName.setText(item.getEffectsId());


        vh1.textViewName.setText(item.getEffectsName());
        vh1.textViewEmail.setText(item.getEffectsId());

        // Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);

        return vh1.rootView;
    }


    private static class ViewHolder1 {
        public final RelativeLayout rootView;
        public final ImageView imageView;
        public final TextView textViewName;
        public final TextView textViewEmail;

        private ViewHolder1(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
            this.rootView = rootView;
            this.imageView = imageView;
            this.textViewName = textViewName;
            this.textViewEmail = textViewEmail;
        }

        public static MyContactAdapter2.ViewHolder1 create(RelativeLayout rootView) {
            ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
            TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
            TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
            return new MyContactAdapter2.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
        }
    }
}

问题出在这一行:

 EffectList item = (EffectList) getItem(position);

您的项目不是EffectList ,它们是Map的列表,您可以在此处看到:

List<Map<String, List<EffectList>>> contactList;

您已重写getItem方法,并从List返回相应的映射。 由于您正在获取getItem调用返回的Map ,因此您需要重新考虑EffectList获取EffectList的逻辑。

我不知道你要用List<Map<String, List<EffectList>>>这个复杂结构做什么,但也许你想要一个List<EffectList

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM