码迷,mamicode.com
首页 > 移动开发 > 详细

android 傻瓜式小错误

时间:2016-07-12 21:01:46      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

技术分享技术分享

报的错误跟原先的异常不一样,只能看懂是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,打断点找错误.

android 傻瓜式小错误

标签:

原文地址:http://www.cnblogs.com/IT-lss/p/5664644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!