• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Error in adding a new contact by coding

adhavan

Lurker
hi i am adding a new contact to emulator
but in LOGCAT i get the error
Code:
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
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

can anyone please spot what is going worng?
my code to add contact is
Code:
[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]
 
[SIZE=2][SIZE=2]ops.add(ContentProviderOperation.[I]newInsert[/I](ContactsContract.Data.[/SIZE]
[LEFT][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CONTENT_URI[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2])[/SIZE]

[COLOR=red][SIZE=2].withValueBackReference(ContactsContract.Data.[/SIZE][I][SIZE=2][SIZE=2]RAW_CONTACT_ID[/SIZE][/SIZE][/I][SIZE=2], 0)[/SIZE][/COLOR]
[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]
[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]
[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]


[SIZE=2].build());[/SIZE]
[SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] {[/SIZE][/SIZE][SIZE=2]
[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]
[SIZE=2]}[/SIZE]

[SIZE=2][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Exception e) {[/SIZE][/SIZE][/LEFT]
[SIZE=2]
 

[LEFT][SIZE=2]Context ctx = getApplicationContext();[/SIZE]
[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]
[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]
[SIZE=2]Toast toast = Toast.[I]makeText[/I](ctx, txt, duration);[/SIZE]
[SIZE=2]toast.show();[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

[/SIZE][/SIZE][/SIZE][/SIZE]
please help me out.
thanks a lot in advance
 
Back
Top Bottom