AndroidRuntime(883):在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)

时间:2012-04-06 16:14:29

标签: android android-contacts android-contentprovider

我在内容提供商上尝试了这个简单的演示代码,但我得到了一个readExceptionFromParcel异常。

Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_FILTER_URI, editText.getText().toString());
    Cursor idCursor = getContentResolver().query(lookupUri, null, null, null, null);

    startManagingCursor(idCursor);        

    String wherestmt = ContactsContract.Data.CONTACT_ID + " = " + idCursor + " And " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Phone.CONTENT_URI + "'";        
    Cursor datacursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,wherestmt,null,null);

    int nameIdx = datacursor.getColumnIndexOrThrow(ContactsContract.Data.DISPLAY_NAME);
    int phoneIdx = datacursor.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER);

    datacursor.moveToFirst();

    list = new ArrayList<String>();

    do{

        String name = datacursor.getString(nameIdx);
        String phone = datacursor.getString(phoneIdx);
        list.add(name + " " + phone);           

    }while(datacursor.moveToNext());

    ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,list);
    listView.setAdapter(adapter);

请帮我解决这个例外。

1 个答案:

答案 0 :(得分:0)

您可以attach the source code到您的项目并查看ContentproviderNative.java,您可以看到通过DatabaseUtils.readExceptionFromParcel(回复)行或使用logcat的异常。大多数情况下,这是因为权限。你是否为你的应用添加了阅读联系人权限?