【问题标题】:Error adding contact in android在android中添加联系人时出错
【发布时间】:2014-10-02 01:01:22
【问题描述】:

我用的是Android Studio,代码:

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

ops.add(ContentProviderOperation.newInsert(
    ContactsContract.RawContacts.CONTENT_URI)
    .withValues(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
    .withValues(ContactsContract.RawContacts.ACCOUNT_NAME, null)
    .build());

错误:

Error:(535, 17) error: method withValues in class Builder cannot be applied to given types;
required: ContentValues
found: String,<null>
reason: actual and formal argument lists differ in length

截图:

【问题讨论】:

    标签: android android-contacts


    【解决方案1】:

    如果你想传递你应该使用的字符串和对象,你选择了错误的方法

    withValue(String key, Object value)
    

    不是

    withValues(ContentValues values)
    

    注意请注意第一个没有 s 而您在代码中使用的第二个使用的是带有 s

    请参阅此以供参考,请参阅 withValue(String key, Object value)withValues(ContentValues values)

    【讨论】:

    • 非常感谢。这是我的愚蠢错误。
    猜你喜欢
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    相关资源
    最近更新 更多