今天我遇到了一个奇怪的错误。我花了很多时间。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("list people size:");
System.out.println(listPeople.size());
listPeople.clear();
ArrayList<PeopleModel> newList = new ArrayList<PeopleModel>();
newList = smsUtils.getPeopleList();
// newList.size() = 42.
for(int i=0;i<newList.size();i++){
System.out.println(i);
listPeople.add(newList.get(i));
}
//**strange error happened in loop above. I don't know why**
// **it loops to infinity and causes outofmemory.**
System.out.println("list new people size:");
System.out.println(newList.size());
if(adapter!=null){
adapter.notifyDataSetChanged();
}
}
});
}
以前,我用过:
listPeople = smsUtils.getPeopleList();
但是发生了另一个奇怪的错误。listPeople
现在有 84 个元素而不是 42 个。
谢谢!