1. Check out our companion app, Forums for Android! Download from Google Play

Exception caught when browsing contacts

Discussion in 'Application Development' started by vikram.patil, Jul 11, 2009.

  1. vikram.patil

    vikram.patil New Member
    Thread Starter
    5

    Jun 29, 2009
    4
    0
    5
    hello,
    i have inserted a contact using a following contacts. This code
    inserts all the required attributes of contacts. But when i go to
    contacts on emulator, and double click on that contact, i get this
    exception

    07-11 10:02:34.211: ERROR/AndroidRuntime(625): Uncaught handler:
    thread main exiting due to uncaught exception
    07-11 10:02:34.302: ERROR/AndroidRuntime(625):
    java.lang.RuntimeException: Unable to resume activity
    {com.android.contacts/com.android.contacts.ViewContactActivity}:
    java.lang.NullPointerException
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.performResumeActivity(ActivityThread.java:
    2632)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.handleResumeActivity(ActivityThread.java:
    2647)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
    2287)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.access$1800(ActivityThread.java:112)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.os.Handler.dispatchMessage(Handler.java:99)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.os.Looper.loop(Looper.java:123)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.main(ActivityThread.java:3948)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    java.lang.reflect.Method.invokeNative(Native Method)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    java.lang.reflect.Method.invoke(Method.java:521)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
    (ZygoteInit.java:782)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    dalvik.system.NativeStart.main(Native Method)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): Caused by:
    java.lang.NullPointerException
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    com.android.contacts.ViewContactActivity.buildEntries
    (ViewContactActivity.java:733)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    com.android.contacts.ViewContactActivity.dataChanged
    (ViewContactActivity.java:313)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    com.android.contacts.ViewContactActivity.onResume
    (ViewContactActivity.java:245)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.Instrumentation.callActivityOnResume(Instrumentation.java:
    1225)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.Activity.performResume(Activity.java:3530)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): at
    android.app.ActivityThread.performResumeActivity(ActivityThread.java:
    2619)
    07-11 10:02:34.302: ERROR/AndroidRuntime(625): ... 12 more

    The code for inserting the contact is as follows ::

    private void testInsertContacts2() {

    ContentValues personValues = new ContentValues();

    //
    // add Name & Notes.

    personValues.put(Contacts.People.NAME, "Doe Nash");
    personValues.put(Contacts.People.NOTES, "HI I M JUST TESTING");

    Uri newPersonUri = getContentResolver().insert
    (People.CONTENT_URI,personValues);

    if (newPersonUri != null) {

    // add mobile phone number

    ContentValues mobileValues = new ContentValues();
    Uri mobileUri = Uri.withAppendedPath
    (newPersonUri,Contacts.People.Phones.CONTENT_DIRECTORY);
    mobileValues.put(Contacts.Phones.NUMBER,"(660) 111-1111");
    mobileValues.put
    (Contacts.Phones.TYPE,Contacts.Phones.TYPE_MOBILE);
    Uri phoneUpdate = getContentResolver().insert(mobileUri,
    mobileValues);

    // add email

    ContentValues emailValues = new ContentValues();
    Uri emailUri = Uri.withAppendedPath
    (newPersonUri,Contacts.People.ContactMethods.CONTENT_DIRECTORY);
    emailValues.put
    (Contacts.ContactMethods.KIND,Contacts.KIND_EMAIL);
    emailValues.put
    (Contacts.ContactMethods.TYPE,Contacts.ContactMethods.TYPE_HOME);
    emailValues.put
    (Contacts.ContactMethods.DATA,"[email address]");
    Uri emailUpdate = getContentResolver().insert(emailUri,
    emailValues);

    // add address

    ContentValues addressValues = new ContentValues();
    Uri addressUri = Uri.withAppendedPath
    (newPersonUri,Contacts.People.ContactMethods.CONTENT_DIRECTORY);
    addressValues.put
    (Contacts.ContactMethods.KIND,Contacts.KIND_POSTAL);
    addressValues.put
    (Contacts.ContactMethods.TYPE,Contacts.ContactMethods.TYPE_HOME);
    addressValues.put(Contacts.ContactMethods.DATA,"Baker Street
    14\n54123 New Hampshire");
    Uri addressUpdate = getContentResolver().insert
    (addressUri,addressValues);

    // add chat address

    ContentValues chataddressValues = new ContentValues();
    Uri chataddressUri = Uri.withAppendedPath
    (newPersonUri,Contacts.People.ContactMethods.CONTENT_DIRECTORY);
    chataddressValues.put
    (Contacts.ContactMethods.KIND,Contacts.KIND_IM);
    chataddressValues.put
    (Contacts.ContactMethods.TYPE,Contacts.ContactMethods.TYPE_HOME);
    chataddressValues.put
    (Contacts.ContactMethods.DATA,"[email address]");
    Uri chataddressUpdate = getContentResolver().insert
    (chataddressUri,chataddressValues);

    // add company (organization)

    ContentValues organisationValues = new ContentValues();
    Uri orgUri = Uri.withAppendedPath
    (newPersonUri,Contacts.Organizations.CONTENT_DIRECTORY);
    organisationValues.put(Contacts.Organizations.COMPANY,"MyCompany
    Inc.");
    organisationValues.put
    (Contacts.Organizations.TYPE,Contacts.Organizations.TYPE_WORK);
    Uri orgUpdate = getContentResolver().insert(orgUri,
    organisationValues);

    }

    }

    plz let me know if there is a solution ...
    Thanks

    Vikram Patil
     

    Advertisement

Share This Page

Loading...