编辑用户时出现运行时错误';Android中的个人资料数据
我希望我的应用程序在Android中修改用户的个人资料联系信息。但是,它一直显示运行时错误,即NullPointerException编辑用户时出现运行时错误';Android中的个人资料数据,android,android-contacts,Android,Android Contacts,我希望我的应用程序在Android中修改用户的个人资料联系信息。但是,它一直显示运行时错误,即NullPointerException private void updateUserProfile(Uri uri, Profile profile) { String mRawContactId = null; Cursor mContactCursor = getContentResolver().query(uri, null, null, null, null); i
private void updateUserProfile(Uri uri, Profile profile) {
String mRawContactId = null;
Cursor mContactCursor = getContentResolver().query(uri, null, null, null, null);
if (mContactCursor.moveToFirst()) {
String mContactId = getCursorString(mContactCursor,
ContactsContract.Contacts._ID);
Cursor mRawContactCursor = getContentResolver().query(
RawContacts.CONTENT_URI,
null,
Data.CONTACT_ID + " = ?",
new String[] {mContactId},
null);
Log.v("RawContact", "Got RawContact Cursor");
try {
ArrayList<String> mRawContactIds = new ArrayList<String>();
while(mRawContactCursor.moveToNext()) {
String rawId = getCursorString(mRawContactCursor, RawContacts._ID);
Log.v("RawContact", "ID: " + rawId);
mRawContactIds.add(rawId);
}
for(String rawId : mRawContactIds) {
// Make sure the "last checked" RawContactId is set locally for use in insert & update.
mRawContactId = rawId;
}
} finally {
mRawContactCursor.close();
}
}
try {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, mRawContactId)
.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE)
.withValue(Data.DATA1, profile.getEmail())
.withValue(Email.TYPE, Email.TYPE_HOME)
.withValue(Email.DISPLAY_NAME, "Email")
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void updateUserProfile(Uri,概要文件){
字符串mRawContactId=null;
Cursor mContactCursor=getContentResolver().query(uri,null,null,null,null);
if(mContactCursor.moveToFirst()){
字符串mContactId=getCursorString(mContactCursor,
联系人合同联系人。\u ID);
游标MRawContectCursor=getContentResolver().query(
rawscontacts.CONTENT_URI,
无效的
Data.CONTACT_ID+“=?”,
新字符串[]{mContactId},
无效);
Log.v(“RawContact”,“Get-RawContact游标”);
试一试{
ArrayList mRawContactIds=新的ArrayList();
while(mRawContactCursor.moveToNext()){
字符串rawId=getCursorString(mRawContactCursor,RawContacts.\u ID);
Log.v(“RawContact”,“ID:+rawId”);
mrawContacts.add(rawId);
}
for(字符串rawId:mRawContactIds){
//确保本地设置了“上次选中”的RawContactId,以便在插入和更新中使用。
mRawContactId=rawId;
}
}最后{
mRawContactCursor.close();
}
}
试一试{
ArrayList ops=新的ArrayList();
add(ContentProviderOperation.newInsert(Data.CONTENT\u URI)
.带值(Data.RAW\u CONTACT\u ID,mRawContactId)
.withValue(Data.MIMETYPE、Email.CONTENT\u ITEM\u TYPE)
.withValue(Data.DATA1,profile.getEmail())
.withValue(Email.TYPE,Email.TYPE\u HOME)
.withValue(Email.DISPLAY_NAME,“Email”)
.build());
getContentResolver().applyBatch(contacts contract.AUTHORITY,ops);
}捕获(远程异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}捕获(操作应用程序异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
我发现它在getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops)行中代码>。但是getContentResolver()
,ContactsContact.AUTHORITY
&ops
中的任何一个都不能为空
谁能告诉我出了什么问题?谢谢你能发布错误日志吗?哦,谢谢,我刚刚修复了它。似乎我不需要mContactCursor来拖动配置文件信息。