向“联系人”添加条目时出错

时间:2016-08-15 13:11:50

标签: android

我试图在“通讯录”中添加条目。如果选择选项"仅限USIM",app" Contacts"已关闭,并且有一个错误的窗口:"不幸的是,联系人已停止"。如果选择任何其他选项,那么效果很好

示例代码:

val intent = Intent (ContactsContract.Intents.Insert.ACTION)
intent.type = ContactsContract.RawContacts.CONTENT_TYPE
intent.putExtra (ContactsContract.Intents.Insert.NAME, contact.name + "" + contact.secondName)
intent.putExtra (ContactsContract.Intents.Insert.PHONE, contact.phoneNumber)
intent.putExtra (ContactsContract.Intents.Insert.EMAIL, contact.email)
startActivity (intent)

LogCat中的异常:

E/AndroidRuntime: FATAL EXCEPTION: main
                                               java.lang.RuntimeException: Failure delivering result ResultInfo{who=android:fragment:0, request=1, result=-1, data=Intent { (has extras) }} to activity {com.android.contacts/com.android.contacts.activities.ContactEditorActivity}: java.lang.NullPointerException
                                                   at android.app.ActivityThread.deliverResults(ActivityThread.java:3302)
                                                   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3345)
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:149)
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348)
                                                   at android.os.Handler.dispatchMessage(Handler.java:99)
                                                   at android.os.Looper.loop(Looper.java:153)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5086)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:511)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
                                                   at dalvik.system.NativeStart.main(Native Method)
                                                Caused by: java.lang.NullPointerException
                                                   at com.android.contacts.model.EntityModifier.canInsert(EntityModifier.java:94)
                                                   at com.android.contacts.model.EntityModifier.parseExtras(EntityModifier.java:625)
                                                   at com.android.contacts.editor.ContactEditorFragment.bindEditorsForNewContact(ContactEditorFragment.java:839)
                                                   at com.android.contacts.editor.ContactEditorFragment.bindEditorsForNewContact(ContactEditorFragment.java:798)
                                                   at com.android.contacts.editor.ContactEditorFragment.createContact(ContactEditorFragment.java:765)
                                                   at com.android.contacts.editor.ContactEditorFragment.onActivityResult(ContactEditorFragment.java:2134)
                                                   at android.app.Activity.dispatchActivityResult(Activity.java:5208)
                                                   at android.app.ActivityThread.deliverResults(ActivityThread.java:3298)
                                                   at android.app.ActivityThread.handleSendResult(ActivityThread.java:3345) 
                                                   at android.app.ActivityThread.access$1100(ActivityThread.java:149) 
                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348) 
                                                   at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                   at android.os.Looper.loop(Looper.java:153) 
                                                   at android.app.ActivityThread.main(ActivityThread.java:5086) 
                                                   at java.lang.reflect.Method.invokeNative(Native Method) 
                                                   at java.lang.reflect.Method.invoke(Method.java:511) 
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821) 
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 
                                                   at dalvik.system.NativeStart.main(Native Method) 

Options to add to contacts

Error

0 个答案:

没有答案