asked for back ref 0 but there are only 0 back refs

Tutorials with advanced 'difficulty' and more Lines of Code.

asked for back ref 0 but there are only 0 back refs

Postby adhavan » Thu Aug 26, 2010 1:20 pm

hi i am adding a new contact from my application.
but in LOGCAT i am getting the error
Code: Select all
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
[color=#BF0040]08-24 18:16:44.863: ERROR/JavaBinder(152): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
08-24 18:16:44.863: ERROR/JavaBinder(152): java.lang.ArrayIndexOutOfBoundsException: asked for back ref 0 but there are only 0 back refs[/color]



can anyone please spot what is going worng?
my code to add contact is

Code: Select all
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
        int rawContactInsertIndex = ops.size();
      ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
      .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
            .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
              .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
              .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
              .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType)
              .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
              .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
              .withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType)             
         .build());
      try {
         
          getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
          Context ctx = getApplicationContext();
          CharSequence txt = "Contact " + name +" added successfully";
          int duration = Toast.LENGTH_LONG;
          Toast toast = Toast.makeText(ctx, txt, duration);
          toast.show();
      } catch (Exception e) {
      }



hey please help me out....... what is the simplest way to add a contact with code????? i have also attached the image of my error in LOGCAT.
PFA.

loads of thanks in advance
Attachments
LogCAT.png
Error Thrown
LogCAT.png (85.72 KiB) Viewed 758 times
adhavan
Freshman
Freshman
 
Posts: 7
Joined: Thu Aug 26, 2010 1:03 pm

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests