我想從我的聯繫人列表中獲取他姓名的電話號碼。我已經使用下面的代碼,但它不能正常工作。告訴我我錯在哪裏。如何從我的聯繫人列表中的人名獲取電話號碼android
try {
cursor_company =getContentResolver().query(ContactsContract.Data.CONTENT_URI,
null,ContactsContract.Data.DISPLAY_NAME+ " = " + "sidharth", null, null);
}
catch(Exception e)
{
System.out.println("this is exception "+e);
}
String phone_number;
while (cursor_company.moveToNext()) {
Phone_number =cursor_company.getString(
cursor_company.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(" this is user no. is"+phone_number);
}
cursor_company.close();
}
例外來了,當我運行該代碼如下
android.database.sqlite.SQLiteException: no such column: bhawana: , while compiling: SELECT data_version, phonetic_name, phonetic_name_style, contact_id, lookup, data12, data11, data10, mimetype, data15, data14, data13, display_name_source, data_sync1, data_sync3, data_sync2, agg_presence.chat_capability AS contact_chat_capability, data_sync4, account_type, custom_ringtone, sp, status_updates.status AS status, data1, data4, data5, data2, data3, sns_id, data8, data9, group_sourceid, data6, account_name, data7, display_name, in_visible_group, display_name_alt, contacts_status_updates.status_res_package AS contact_status_res_package, is_primary, contacts_status_updates.status_ts AS contact_status_ts, raw_contact_id, times_contacted, contacts_status_updates.status AS contact_status, status_updates.status_res_package AS status_res_package, status_updates.status_icon AS status_icon, contacts_status_updates.status_i
有什麼異常? – Sameer 2012-03-30 07:33:58
是的例外是「找不到列」我也可以顯示你完整的一個,如果你想第一眼看到 – 2012-03-30 07:36:59
我沒有看到你的代碼有什麼問題。你能告訴我們什麼是問題嗎?爲什麼它不能正常工作?什麼是返回? – Th0rndike 2012-03-30 07:37:55