android.database.sqlite.SQLiteException:未知错误(代码0):无法将BLOB转换为字符串

时间:2017-07-28 05:47:21

标签: android android-contacts

我在更新现有联系人中的姓名时收到此错误。我的代码:

String nameWhere = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='"
            + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";

String[] idParam = new String[]{contacts.getContactId()};

    ContentValues values = new ContentValues();
    values.put(ContactsContract.Contacts.Data.RAW_CONTACT_ID, id);
    values.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, contacts.getName());
    int update = context.getContentResolver().update(ContactsContract.Data.CONTENT_URI, values, nameWhere, idParam);

我也经历过这些链接: SQLiteException Unable to convert BLOB to string when contact have photo. Android 和其他与此问题有关。

和我的日志

E / AndroidRuntime:致命异常:主要                                                                        处理:com.embedded.contacts,PID:15248                                                                        android.database.sqlite.SQLiteException:未知错误(代码0):无法将BLOB转换为字符串                                                                        ################################################## ###############                                                                        错误代码:0(SQLITE_OK)                                                                        引发者:未知错误(代码0):无法将BLOB转换为字符串                                                                        ################################################## ###############                                                                        ################################################## ###############                                                                        错误代码:0(SQLITE_OK)                                                                        引发者:未知错误(代码0):无法将BLOB转换为字符串                                                                        ################################################## ###############                                                                        错误代码:0(SQLITE_OK)                                                                        引发者:未知错误(代码0):无法将BLOB转换为字符串                                                                        ################################################## ###############                                                                        ################################################## ###############                                                                            在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179)                                                                            在android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)                                                                            在android.content.ContentProviderProxy.update(ContentProviderNative.java:568)

1 个答案:

答案 0 :(得分:0)

您的代码正在修改两个值:RAW_CONTACT_IDDISPLAY_NAME。 问题是RAW_CONTACT_ID是只读的。 我假设你打算不打算修改raw-contact-id。 如果您只想根据其ID修改联系人DISPLAY_NAME,请尝试以下操作:

String selection = Data.CONTACT_ID + "=" + contacts.getContactId() + " AND " + Data.MIMETYPE + "='" + StructuredName.CONTENT_ITEM_TYPE + "'";
ContentValues values = new ContentValues();
values.put(StructuredName.DISPLAY_NAME, contacts.getName()); // make sure getName() returns a String!!!
getContentResolver().update(Data.CONTENT_URI, values, selection, null);

(确认您导入了DataStructuredName

的正确类别