我有一个自定义列表视图,其中每个列表项有5个条目,这些条目来自SQLite 数据库。此列表视图中有8个列表项。我的自定义适配器代码是:
public class VaccinListAdapter extends BaseAdapter
{
private Context context;
private List<VaccinInfoPOJO> vaccinInfo;
public VaccinListAdapter(Context c,List<VaccinInfoPOJO> list)
{
context=c;
vaccinInfo=list;
}
@Override
public int getCount() {
return vaccinInfo.size();
}
@Override
public Object getItem(int pos) {
return vaccinInfo.get(pos);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
ViewHolder holder;
VaccinInfoPOJO entry=vaccinInfo.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.vaccin_list_style, null);
holder=new ViewHolder();
holder.diseasevalue=(TextView)convertView.findViewById(R.id.vaccin_lv_disease);
holder.animals=(TextView)convertView.findViewById(R.id.vaccin_lv_animalnames);
holder.vaccinname= (TextView)convertView.findViewById(R.id.vaccin_lv_vaccinname);
holder.dosevalue=(TextView)convertView.findViewById(R.id.vaccin_lv_dosagevalue);
holder.timevalue= (TextView)convertView.findViewById(R.id.vaccin_lv_timevalue);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.diseasevalue.setText(entry.getDisease());
holder.animals.setText(entry.getAnimal());
holder.vaccinname.setText(entry.getVaccine());
holder.dosevalue.setText(entry.getDose());
holder.timevalue.setText(entry.getTime());
return convertView;
}
}
我正在使用此ViewHolder类建议here:
static class ViewHolder
{
TextView diseasevalue,animals,vaccinname,dosevalue,timevalue;
}
我在这个增长堆序列的长流::
之后出现了内存异常04-18 09:42:46.033: DEBUG/dalvikvm(370): GC_CONCURRENT freed 45K, 21% free 10597K/13255K, external 1055K/1567K, paused 10ms+10ms
04-18 09:42:48.154: INFO/dalvikvm-heap(370): Clamp target GC heap from 17.901MB to 16.000MB
04-18 09:42:48.154: DEBUG/dalvikvm(370): GC_CONCURRENT freed 68K, 18% free 12622K/15303K, external 1055K/1567K, paused 10ms+11ms
04-18 09:42:48.673: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:48.673: DEBUG/dalvikvm(370): GC_CONCURRENT freed <1K, 18% free 12754K/15367K, external 1055K/1567K, paused 11ms+12ms
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:48.893: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12754K/15367K, external 1055K/1567K, paused 219ms
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.030MB to 16.000MB
04-18 09:42:48.893: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:49.194: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.030MB to 16.000MB
04-18 09:42:49.194: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12754K/15367K, external 1055K/1567K, paused 219ms
04-18 09:42:49.204: INFO/dalvikvm-heap(370): Forcing collection of SoftReferences for 24-byte allocation
04-18 09:42:49.414: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:49.414: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 14K, 18% free 12740K/15367K, external 1055K/1567K, paused 212ms
04-18 09:42:49.414: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.015MB to 16.000MB
04-18 09:42:49.794: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:49.794: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 6ms+6ms
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:50.014: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 214ms
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:50.014: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 60-byte allocation
04-18 09:42:50.314: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:50.314: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 223ms
04-18 09:42:50.324: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:50.324: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 8-byte allocation
04-18 09:42:50.724: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:50.724: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 16ms+5ms
04-18 09:42:50.994: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.015MB to 16.000MB
04-18 09:42:50.994: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed <1K, 18% free 12740K/15367K, external 1055K/1567K, paused 247ms
04-18 09:42:51.004: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.004: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:51.304: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.304: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 226ms
04-18 09:42:51.314: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.314: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 24-byte allocation
04-18 09:42:51.724: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.724: DEBUG/dalvikvm(370): GC_CONCURRENT freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 20ms+6ms
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Clamp target GC heap from 18.016MB to 16.000MB
04-18 09:42:51.934: DEBUG/dalvikvm(370): GC_FOR_MALLOC freed 0K, 18% free 12740K/15367K, external 1055K/1567K, paused 207ms
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Clamp target GC heap from 16.016MB to 16.000MB
04-18 09:42:51.934: INFO/dalvikvm-heap(370): Grow heap (frag case) to 16.000MB for 8-byte allocation
现在去哪儿了?任何帮助都会很明显。
修改::
我犯了一个很大的愚蠢错误。当我运行循环以使用数据填充Arraylist时,循环就像:
for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToFirst())
这里最后一次移动ToFirst将此循环变为无限状态。我将它改为moveToNext。哇...上帝保佑我。!!!