如果我們快速滾動Listview
,應用程序會拋出致命異常OutofMemoryError
。滾動ListView時拋出OutofMemoryException
它滾動時總是給出相同的錯誤。如何處理它?
public class UpcomingAdapter extends BaseAdapter{
Typeface typeFace;
private ArrayList<String> mEventName,mDate,mTime;
private LayoutInflater mInflater;
public UpcomingAdapter(LayoutInflater mInflater,
ArrayList<String> mDEventName,
ArrayList<String> mDdate,
ArrayList<String> mDtime,
Typeface typeface)
{
this.mEventName=mDEventName;
this.mDate=mDdate;
this.mTime=mDtime;
this.mInflater=mInflater;
this.typeFace=typeface;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View view, ViewGroup parent) {
ViewHolder holder = null;
if(view==null) {
holder=new ViewHolder();
view=mInflater.inflate(R.layout.upcomingevent_list,null);
view.setTag(holder);
holder=(ViewHolder) view.getTag();
holder.holderDate=(TextView)view.findViewById(R.id.xTvUpcomingEvents_DateList);
holder.holderEventName=(TextView)view.findViewById(R.id.xTvUpcomingEvents_Events);
holder.holderEventName.setTypeface(typeFace);
holder.holderDate.setTypeface(typeFace);
} else {
holder=(ViewHolder) view.getTag();
}
//holder.employeeName.setTag(mEmpIds.get(arg0));
setText(mEventName.get(arg0), holder.holderEventName);
setText(mDate.get(arg0), holder.holderDate);
setText(mTime.get(arg0), holder.holderEventName);
holder.holderEventName.setTag(mEventName.get(arg0));
holder.holderEventName.setTypeface(typeFace);
//holder.holderArtistId.setTypeface(typeFace);
return view;
}
public static class ViewHolder{
TextView holderEventName;
TextView holderDate;
//TextView holderArtistId;
}
private void setText(String data,TextView view){
if(data.equals(StaticUtils.sNullString)){
view.setText(StaticUtils.sEmptyString);
} else {
view.setText(data);
}
}
}
這是錯誤:
08-17 15:08:22.950: E/AndroidRuntime(25423): FATAL EXCEPTION: main
08-17 15:08:22.950: E/AndroidRuntime(25423): java.lang.OutOfMemoryError: [memory exhausted]
08-17 15:08:22.950: E/AndroidRuntime(25423): at dalvik.system.NativeStart.main(Native Method)
你的例外沒有了嗎? – 2012-09-26 11:13:49