Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android中的联系人加载程序获取电话号码:投影崩溃_Android_Android Contacts_Android Loadermanager_Android Loader - Fatal编程技术网

从android中的联系人加载程序获取电话号码:投影崩溃

从android中的联系人加载程序获取电话号码:投影崩溃,android,android-contacts,android-loadermanager,android-loader,Android,Android Contacts,Android Loadermanager,Android Loader,我使用的示例代码来自。投影是我指定要收集的数据的地方。如何指定我想要电话号码?谷歌的样本没有电话号码。但是我想获得电话号码,所以我为phone.number添加了字段。但当我这样做时,应用程序总是崩溃。这是我的预测 // The projection for the CursorLoader query. This is a list of columns that the Contacts // Provider should return in the Cursor.

我使用的示例代码来自。投影是我指定要收集的数据的地方。如何指定我想要电话号码?谷歌的样本没有电话号码。但是我想获得电话号码,所以我为
phone.number
添加了字段。但当我这样做时,应用程序总是崩溃。这是我的预测

// The projection for the CursorLoader query. This is a list of columns that the Contacts
        // Provider should return in the Cursor.
        @SuppressLint("InlinedApi")
        final static String[] PROJECTION = {

            // The contact's row id
            Contacts._ID,

            // A pointer to the contact that is guaranteed to be more permanent than _ID. Given
            // a contact's current _ID value and LOOKUP_KEY, the Contacts Provider can generate
            // a "permanent" contact URI.
            Contacts.LOOKUP_KEY,

            // In platform version 3.0 and later, the Contacts table contains
            // DISPLAY_NAME_PRIMARY, which either contains the contact's displayable name or
            // some other useful identifier such as an email address. This column isn't
            // available in earlier versions of Android, so you must use Contacts.DISPLAY_NAME
            // instead.
            Utils.hasHoneycomb() ? Contacts.DISPLAY_NAME_PRIMARY : Contacts.DISPLAY_NAME,

            // In Android 3.0 and later, the thumbnail image is pointed to by
            // PHOTO_THUMBNAIL_URI. In earlier versions, there is no direct pointer; instead,
            // you generate the pointer from the contact's ID value and constants defined in
            // android.provider.ContactsContract.Contacts.
            Utils.hasHoneycomb() ? Contacts.PHOTO_THUMBNAIL_URI : Contacts._ID,

            // The sort order column for the returned Cursor, used by the AlphabetIndexer
            SORT_ORDER,

            // Contacts.HAS_PHONE_NUMBER,
            //
            CommonDataKinds.Phone.NUMBER,

        };

        // The query column numbers which map to each value in the projection
        final static int ID = 0;
        final static int LOOKUP_KEY = 1;
        final static int DISPLAY_NAME = 2;
        final static int PHOTO_THUMBNAIL_DATA = 3;
        final static int SORT_KEY = 4;
        // final static int HAS_PHONE_NUMBER = 5;
        final static int PHONE_NUMBER = 5;
    }
这是错误跟踪

12-18 10:20:54.299: E/AndroidRuntime(1909): FATAL EXCEPTION: ModernAsyncTask #1
12-18 10:20:54.299: E/AndroidRuntime(1909): java.lang.RuntimeException: An error occured while executing doInBackground()
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.ModernAsyncTask$3.done(ModernAsyncTask.java:137)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.lang.Thread.run(Thread.java:841)
12-18 10:20:54.299: E/AndroidRuntime(1909): Caused by: java.lang.IllegalArgumentException: Invalid column data1
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.content.ContentProviderProxy.query(ContentProviderNative.java:385)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.content.ContentResolver.query(ContentResolver.java:417)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.content.ContentResolver.query(ContentResolver.java:360)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:35)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:242)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:51)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:40)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at android.support.v4.content.ModernAsyncTask$2.call(ModernAsyncTask.java:123)
12-18 10:20:54.299: E/AndroidRuntime(1909):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-18 10:20:54.299: E/AndroidRuntime(1909):     ... 3 more

这是因为此URI不支持获取
CommonDataTypes.Phone.NUMBER
字段。您应该向
CommonDataTypes.Phone.CONTENT\u URI
发出请求。查看如何在获取联系人姓名和电话时使用此URI