联系人姓名变为空,而光标包含所有联系人

Contacts name are coming null while cursor has all contacts

I'm getting 'name = null' in this code, while cursor has all my contacts in it, i tried many different ways but it all does the same thing.

String[] contact_names, mobile_numbers;

Cursor cursor = getActivity().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,null, null, null);

        while (cursor.moveToFirst()) {

            String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
            String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

            contact_names[contact_names.length] = name;

            Cursor phones = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?" + contactId, null, null);
            while (phones.moveToNext()) {
                String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));

                mobile_numbers[mobile_numbers.length] = number;
            }
            phones.close();
        }
        cursor.close();

不需要多次查询,使用下面一次查询全部搞定,

String[] PROJECTION_MAIN = new String[]{
                ContactsContract.Contacts._ID,
                ContactsContract.CommonDataKinds.Phone.NUMBER,
                ContactsContract.Contacts.DISPLAY_NAME
        };

Cursor cursor = getActivity().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                    PROJECTION_MAIN, null, null, null);

while (cursor.moveToNext()) {
                    String contact_id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                    String phone = cleanNumber(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)), context);

}