无法在设备Letv le x507上加载联系人

时间:2016-02-09 07:04:52

标签: android

获取

  

java.lang.IllegalStateException:无法读取第0行,第1行   CursorWindow。确保之前正确初始化了Cursor   从中访问数据。

在Letv le X507设备上加载联系人时。 代码段

private static final String[] FRIEND_CONTACT_LOOKUP_PROJECTION = new String[]{
        ContactsContract.PhoneLookup.DISPLAY_NAME,
        ContactsContract.PhoneLookup.PHOTO_ID
};

public static ContactInfo contactNameLookup(Context context, String phoneNumber) {

    Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    Cursor cursor = context.getContentResolver().query(uri, FRIEND_CONTACT_LOOKUP_PROJECTION, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
    ContactInfo contact = null;
    if (cursor != null) {
        try {
            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                // CODE to get data from cursor.
            }
        } finally {
            cursor.close();
        }
    }
    return contact;
}

在行 context.getContentResolver()。query(uri,FRIEND_CONTACT_LOOKUP_PROJECTION,null,null,ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME +" COLLATE LOCALIZED ASC")中遇到异常

logcat的

Fatal Exception: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
   at android.os.Parcel.readException(Parcel.java:1548)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
   at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
   at android.content.ContentProviderProxy.query(ContentProviderNative.java:420)
   at android.content.ContentResolver.query(ContentResolver.java:485)
   at android.content.ContentResolver.query(ContentResolver.java:429)
   at com.daamitt.walnut.app.components.ContactsUtil.contactNameLookup(ContactsUtil.java:190)
   at com.daamitt.walnut.app.components.Group.newInstanceFromWalnutGroup(Group.java:722)
   at com.daamitt.walnut.app.components.SplitApi$getGroupsTask.onPostExecute(SplitApi.java:163)
   at com.daamitt.walnut.app.components.SplitApi$getGroupsTask.onPostExecute(SplitApi.java:91)
   at android.os.AsyncTask.finish(AsyncTask.java:632)
   at android.os.AsyncTask.access$600(AsyncTask.java:177)
   at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
   at android.os.Handler.dispatchMessage(Handler.java:111)
   at android.os.Looper.loop(Looper.java:194)
   at android.app.ActivityThread.main(ActivityThread.java:5589)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)

0 个答案:

没有答案