Error in adding a new contact by coding


Last Updated:

  1. adhavan

    adhavan Member This Topic's Starter

    Joined:
    Aug 23, 2010
    Messages:
    6
    Likes Received:
    0
    hi i am adding a new contact to emulator
    but in LOGCAT i get the error
    Code (Text):
    1.  
    2. 08-24 18:16:44.833: ERROR/ContentProviderOperation(152): mType: 1, mUri: content://com.android.contacts/data, mSelection: null, mExpectedCount: null, mYieldAllowed: false, mValues: data1=xzzsf mimetype=vnd.android.cursor.item/name, mValuesBackReferences: raw_contact_id=0, mSelectionArgsBackReferences: null
    3. 08-24 18:16:44.863: ERROR/JavaBinder(152): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
    4. 08-24 18:16:44.863: ERROR/JavaBinder(152): java.lang.ArrayIndexOutOfBoundsException: asked for back ref 0 but there are only 0 back refs
    5.  
    can anyone please spot what is going worng?
    my code to add contact is
    Code (Text):
    1.  
    2. [SIZE=2]ArrayList<ContentProviderOperation> ops = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ArrayList<ContentProviderOperation>();[/SIZE]
    3.  
    4. [SIZE=2][SIZE=2]ops.add(ContentProviderOperation.[I]newInsert[/I](ContactsContract.Data.[/SIZE]
    5. [LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CONTENT_URI[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]
    6.  
    7. [COLOR=red][SIZE=2].withValueBackReference(ContactsContract.Data.[/SIZE][I][SIZE=2][SIZE=2]RAW_CONTACT_ID[/SIZE][/SIZE][/I][SIZE=2], 0)[/SIZE][/COLOR]
    8. [LEFT][SIZE=2].withValue(ContactsContract.Data.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]MIMETYPE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2],[/SIZE]
    9. [SIZE=2]ContactsContract.CommonDataKinds.StructuredName.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CONTENT_ITEM_TYPE[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]
    10. [SIZE=2].withValue(ContactsContract.CommonDataKinds.StructuredName.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]DISPLAY_NAME[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], name)[/SIZE][/LEFT]
    11.  
    12.  
    13. [SIZE=2].build());[/SIZE]
    14. [SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE][/SIZE][SIZE=2]
    15. [SIZE=2][SIZE=2]getContentResolver().applyBatch(ContactsContract.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]AUTHORITY[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], ops);[/SIZE][/SIZE][SIZE=2]
    16. [SIZE=2]}[/SIZE]
    17.  
    18. [SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Exception e) {[/SIZE][/SIZE][/LEFT]
    19. [SIZE=2]
    20.  
    21.  
    22. [LEFT][SIZE=2]Context ctx = getApplicationContext();[/SIZE]
    23. [LEFT][SIZE=2]CharSequence txt = getString(R.string.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]contactCreationFailure[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
    24. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] duration = Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE]
    25. [SIZE=2]Toast toast = Toast.[I]makeText[/I](ctx, txt, duration);[/SIZE]
    26. [SIZE=2]toast.show();[/SIZE]
    27. [SIZE=2]}[/SIZE][/LEFT]
    28. [/LEFT]
    29.  
    30. [/SIZE][/SIZE][/SIZE][/SIZE]
    please help me out.
    thanks a lot in advance
     

    Advertisement

Share This Page

Loading...