1

すばやくスクロールするListviewと、アプリは Fatal Exception をスローしますOutofMemoryError

スクロール中に常に同じエラーが発生します。対処方法は?

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)
4

3 に答える 3

1

あなたの getView メソッドで試してください:

@Override
    public View getView(int arg0, View view, ViewGroup parent) {


        if(view==null) {
            LayoutInflater layoutInflater=LayoutInflater.from(getContext());
            view=layoutInflater.inflate(R.layout.upcomingevent_list, parent, false);
            holder=new ViewHolder();
            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);
            view.setTag(holder);
        } 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;
    }
于 2012-08-22T05:04:54.420 に答える
0

アクティビティがメモリ不足を検出したときに、アクティビティのonLowMemory()メソッドをオーバーライドし、ガベージコレクターを実行することもできます。System.gc()を使用できます。また、このメソッドの不要な変数を無効にします。

于 2013-03-08T08:25:41.203 に答える
-2

以下のメソッドを既存のコードに置き換えます。

   @Override
        public int getItem(int position) {
            return <Return Particular int variable from Data>;
        }

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return <Return Particular int variable from Data>;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return <Return Particular int variable from Data>;
}
于 2012-08-17T04:36:32.773 に答える