我在 bulkInsert 上收到 nullPointerException。不知道为什么。ContentValues 似乎是正确的。我不确定我是否将其正确转换为 CV 数组。
if (contactList != null && !contactList.isEmpty()) {
ContentValues cv = new ContentValues();
List<ContentValues>valueList = new ArrayList<ContentValues>();
ContentValues[] vc = new ContentValues[contactList.size()];
for (HashMap<String, Object> userDict : contactList) {
progress.setProgress(contactsLoaded);
// Initialize values we're looking for. In this case, cn (common name), sn (surname), alias, sipExt.
String cn = userDict.get("cn").toString();
String sn = userDict.get("sn").toString();
String alias = userDict.get("username").toString();
String sipExt = userDict.get("sipExt").toString();
cv = new ContentValues();
cv.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
cv.put(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, cn);
cv.put(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, sn);
cv.put(ContactsContract.CommonDataKinds.StructuredName.PREFIX, alias);
cv.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, sipExt);
valueList.add(cv);
contactsLoaded++;
}
System.out.println("CV: "+valueList);
vc = valueList.toArray(vc);
System.out.println("VC: "+vc);
myActivity.getContentResolver().bulkInsert(ContactsContract.Data.CONTENT_URI, vc);
}