报的错误跟原先的异常不一样,只能看懂是oom内存溢出,错误代码如下:
private void getPersons(){ String path="content://com.lss.readcontactmassage.PersonDBProvider/query"; Uri uri = Uri.parse(path); ContentResolver contentResolver = getContentResolver(); Cursor cursor = contentResolver.query(uri, null, null, null, null); persons=new ArrayList<Person>(); if (cursor==null){ return; } while (cursor.moveToLast()){ int id = cursor.getInt(cursor.getColumnIndex("id")); String name = cursor.getString(cursor.getColumnIndex("name")); String number = cursor.getString(cursor.getColumnIndex("number")); Person person = new Person(id, name, number); persons.add(person); } cursor.close(); }
while构成了死循环,所以造成内存溢出,这种不常见的错误遇到时不要慌,学会使用debug,打断点找错误.