当我的应用程序正在阅读时联系错误显示java.lang.IllegalArgumentException:无效的列account_name

时间:2018-01-18 21:29:03

标签: android

我正在尝试获取设备中所有联系人的帐户名称和帐户类型,但我收到错误帐号名无效。

使用的代码:

private static final String [] CONTACT_PROJECTION = new String [] { "_id", 
            "lookup",
            "display_name",
            "display_name_alt",
            "display_name_source",
            "phonetic_name",
            "phonetic_name_style",
            "sort_key",
            "sort_key_alt",
            "photo_id",
            "photo_uri",
            "photo_thumb_uri"
            "in_visible_group",
            "has_phone_number",
            "times_contacted",
            "last_time_contacted",
            "starred",
            "custom_ringtone",
            "send_to_voicemail",
            "contact_presence",
            "contact_status",
            "contact_status_ts",
            "contact_status_res_package",
            "contact_status_label",
            "contact_status_icon",
            ContactsContract.RawContacts.ACCOUNT_NAME,
            ContactsContract.RawContacts.ACCOUNT_TYPE,
    };
public int readContact(String selection, String[] selectionArgs) {
        String isStarred = selectionArgs[0];
        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, CONTACT_PROJECTION,
                selection, selectionArgs, "sort_key");
        String flag = "first";
        while (cursor.moveToNext()) {

            long _id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
            String accountName = cursor.getString(cursor.getColumnIndex(
                    ContactsContract.RawContacts.ACCOUNT_NAME));
            String accountType = cursor.getString(cursor.getColumnIndex(
                    ContactsContract.RawContacts.ACCOUNT_TYPE));

帮助我,我错了 我的logcat日志:

01-19 02:39:33.707 8986-9048/com.wangyeming.foxchat E/AndroidRuntime: FATAL EXCEPTION: Thread-129
                                                                      Process: com.wangyeming.foxchat, PID: 8986
                                                                      java.lang.IllegalArgumentException: Invalid column account_name
                                                                          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
                                                                          at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
                                                                          at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
                                                                          at android.content.ContentResolver.query(ContentResolver.java:461)
                                                                          at android.content.ContentResolver.query(ContentResolver.java:404)
                                                                          at com.wangyeming.foxchat.NewContactFragment.readContact(NewContactFragment.java:298)
                                                                          at com.wangyeming.foxchat.NewContactFragment.getPhoneContacts(NewContactFragment.java:265)
                                                                          at com.wangyeming.foxchat.NewContactFragment$1.run(NewContactFragment.java:183)
                                                                          at java.lang.Thread.run(Thread.java:841)

1 个答案:

答案 0 :(得分:1)

名称错误,请在使用ACCOUNT_NAME时检入每个代码。验证ContactsContract。