2011-05-09 143 views
0

我有這樣的代碼:試圖將值添加到聯繫人

String cName = name.getText().toString(); 
String cPhone = phone.getText().toString(); 
String cMail = email.getText().toString(); 
int cPhoneType = mContactPhoneTypes.get(mContactPhoneTypeSpinner.getSelectedItemPosition()); 
int cEmailType = mContactEmailTypes.get(mContactEmailTypeSpinner.getSelectedItemPosition()); 

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
int rowContactInsertIndex = ops.size(); 

ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, mSelectedAccount.getType()).withValue(ContactsContract.RawContacts.ACCOUNT_NAME, mSelectedAccount.getName()).build()); 
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rowContactInsertIndex).withValue(ContactsContract.Data.DATA1,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,cName).build()); 
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rowContactInsertIndex).withValue(ContactsContract.Data.DATA1, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, cPhone).withValue(ContactsContract.CommonDataKinds.Phone.TYPE, cPhoneType).build()); 
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI).withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rowContactInsertIndex).withValue(ContactsContract.Data.DATA1, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE).withValue(ContactsContract.CommonDataKinds.Email.DATA, cMail).withValue(ContactsContract.CommonDataKinds.Email.TYPE, cEmailType).build()); 

try { 
    ContentProviderResult[] res = getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
} catch(Exception e) { 
    Context context = getApplicationContext(); 
    CharSequence txt = getString(R.string.contactCreationFailure); 
    Toast.makeText(context, txt, Toast.LENGTH_LONG).show(); 
} 

但我發現了以下錯誤:

android.database.sqlite.SQLiteException: table raw_contacts has no column named data1: , while compiling: INSERT INTO raw_contacts(contact_id, data1, raw_contact_id) VALUES(?, ?, ?);

任何想法?提前致謝。

+0

**歡迎使用StackOverflow!**請將精力投入到您的帖子中;他們是讓他人理解你的意思的媒介。 ;-) 謝謝! – 2011-05-09 18:30:09

回答

相關問題