Android:视图持有者的classCastException

时间:2012-12-19 11:45:08

标签: android

我有一个适配器,我试图将联系人详细信息检索到列表视图

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

    View view = convertView; 
    final ViewHolder holder;
    if (view == null) { 
    view = inflater.inflate(R.layout.profile, null); 
    holder = new ViewHolder();
    holder.text = (TextView) view.findViewById(R.id.name);
    holder.textContNo = (TextView) view.findViewById(R.id.contactno);
    holder.textEmailId = (TextView) view.findViewById(R.id.emailId); 
    view.setTag(holder);
    } else
        holder = (ViewHolder) view.getTag();


    Profile contact = listCont.get(position); 
    holder.text.setText(contact.getName()); 

    QuickContactBadge photo = (QuickContactBadge ) view.findViewById(R.id.quickContactBadge1);  
    photo.setTag(contact.getMobileNo()); 
    new LoadImage(photo).execute(contact.getMobileNo()); 

我在日志中收到了follogin错误

FATAL EXCEPTION: main
12-19 17:07:27.080: E/AndroidRuntime(6988): java.lang.ClassCastException: org.appright.myneighborhood.data.Profile cannot be cast to org.appright.myneighborhood.adaptor.ProfileAdapter$ViewHolder
12-19 17:07:27.080: E/AndroidRuntime(6988):     at org.appright.myneighborhood.adaptor.ProfileAdapter.getView(ProfileAdapter.java:82)
12-19 17:07:27.080: E/AndroidRuntime(6988):     at android.widget.AbsListView.obtainView(AbsListView.java:1949)
12-19 17:07:27.080: E/AndroidRuntime(6988):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1228)

在此行附近获取classcastexception:holder =(ViewHolder)view.getTag(); 在哪里我做错了,感谢任何帮助

1 个答案:

答案 0 :(得分:0)

我认为这样的返回类型声明,

return view;