2016-12-29 14 views
1

retrofitを使用してjsonを解析しようとしています。BaseAdapterを使用してリストビューに値を表示しようとしています。 BaseAdapter内のマップを使用しているときに、次のエラーが発生しています。java.lang.ClassCastException:com.google.gson.internal.LinkedTreeMapをcom.exampleにキャストできません

とjava.lang.ClassCastException:com.google.gson.internal.LinkedTreeMapはcom.example.prakash.pix91.getでcom.example.prakash.pix91.get.Templates.pixjson.EffectListにキャストすることはできません。 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); 
     } 
    } 
} 
+0

あなたの 'JSON'は"あなたが望むように "解析されていないようです。 –

答えて

0

問題は、このラインである:

EffectList item = (EffectList) getItem(position); 

あなたの項目がEffectListのではありません、彼らはMapのリストなどをしていますあなたはここに見ることができます:

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

getItemメソッドをオーバーライドし、リストから適切なマップを返します。 getItemコールで返されたMapがあるので、EffectListを取得するロジックを再考する必要があります。

List<Map<String, List<EffectList>>>のこの複雑な構造で何をしようとしているのか分かりませんが、List<EffectListが必要なのでしょうか?

関連する問題