找到不兼容的类型java.lang:ArrayAdapter

找到不兼容的类型java.lang:ArrayAdapter,java,android,android-arrayadapter,Java,Android,Android Arrayadapter,当我在代码行下面尝试时 ItemRow itemdata = data.get(position); 在ItemAdapter类中,我得到了错误 需要不兼容的类型:com.fragment.ItemRow找到:java.lang.object 完整的ItemRow.java类如下所示: Package com.fragments; import android.graphics.drawable.Drawable; public class ItemRow { String itemNa

当我在代码行下面尝试时

ItemRow itemdata = data.get(position);
在ItemAdapter类中,我得到了错误

需要不兼容的类型:com.fragment.ItemRow找到:java.lang.object

完整的ItemRow.java类如下所示:

Package com.fragments;

import android.graphics.drawable.Drawable;

public class ItemRow {

String itemName;
Drawable icon;

public ItemRow(String itemName, Drawable icon) {
    super();
    this.itemName = itemName;
    this.icon = icon;
}

public String getItemName() {
    return itemName;
}
public void setItemName(String itemName) {
    this.itemName = itemName;
}
public Drawable getIcon() {
    return icon;
}
public void setIcon(Drawable icon) {
    this.icon = icon;
}

}
还有一个完整的Itemadapeter类,我在其中尝试时得到了不兼容的类型

-ItemRow itemdata=data.get(位置);在getView中

package com.fragments;
public class ItemAdapter extends ArrayAdapter {

List   data;
Context context;
int layoutResID;

public ItemAdapter(Context context, int layoutResourceId,List data) {
    super(context, layoutResourceId, data);

    this.data=data;
    this.context=context;
    this.layoutResID=layoutResourceId;

    // TODO Auto-generated constructor stub
 }

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

    NewsHolder holder = null;
    View row = convertView;
    holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResID, parent, false);

        holder = new NewsHolder();

        holder.itemName = (TextView)row.findViewById(R.id.example_itemname);
        holder.icon=(ImageView)row.findViewById(R.id.example_image);
        holder.button1=(Button)row.findViewById(R.id.swipe_button1);
        holder.button2=(Button)row.findViewById(R.id.swipe_button2);
        holder.button3=(Button)row.findViewById(R.id.swipe_button3);
        row.setTag(holder);
    }
    else
    {
        holder = (NewsHolder)row.getTag();
    }

    ItemRow itemdata = data.get(position);


    holder.itemName.setText(itemdata.getItemName());
    holder.icon.setImageDrawable(itemdata.getIcon());

    holder.button1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Button 1 Clicked",Toast.LENGTH_SHORT).show();
        }
    });

    holder.button2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Button 2 Clicked",Toast.LENGTH_SHORT).show();
        }
    });

    holder.button3.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(context, "Button 3 Clicked",Toast.LENGTH_SHORT);
        }
    });

    return row;

}

static class NewsHolder{

    TextView itemName;
    ImageView icon;
    Button button1;
    Button button2;
    Button button3;
}

}

您的列表是
raw type
mean
Object
,因此您必须将
Object
向下投射到您的POJO,即
ItemRow

ItemRow itemdata = (ItemRow )data.get(position);

或者您应该有一个
list
类型的列表,因为不知道您要传递给这个适配器的是哪种类型的列表,所以请确保在这种情况下传递与
list
相同的类型,并遵循最佳实践,将带有适配器的类型称为扩展阵列适配器,并在其他位置进行所需的更改。

请使用
列表
而不是
列表

该问题是由
ItemAdapter

List data;
相反,试试这个

ArrayList<ItemRow> data;
ArrayList数据;
原始列表数据;为什么?