6
我有一個適配器上IAM試圖檢索聯繫人詳細信息到一個ListView安卓:ClassCastException異常的觀點持有者
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(); 我在哪裏做錯了,任何幫助表示讚賞
您獲得的例外,因爲view.getTag()將返回的對象和你試圖強制轉換它在ViewHolder –
嘗試完成與您的'else'語句括號 – mango
@ Shreya Shah plz建議我該怎麼辦 – teekib