1
軟件和模擬器版本我使用IndexOutOfBoundsException異常更新的聯繫人列表中的聯繫人時 - 黑莓
BlackBerry智能手機模擬器:2.13.0.65
黑莓軟件版本5.0.0_5.0.0.14
我我正在修改聯繫人。以下是我使用的代碼片段。 我在行
String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]);
得到一個IndexOutOfBounds異常可有人建議是怎麼回事錯在這裏。以下是代碼片段
.....
// Load the addressbook and let the user choose from list of contact
BlackBerryContactList contactList = (BlackBerryContactList) PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_WRITE);
PIMItem pimItem = contactList.choose();
BlackBerryContact blackBerryContact = (BlackBerryContact)pimItem;
PIMList pimList = blackBerryContact.getPIMList();
// get the supported attributes for Contact.TEL
int[] supportedAttributes = pimList.getSupportedAttributes(Contact.TEL);
Dialog.alert("Supported Attributes "+supportedAttributes.length); // gives me 8
for (int i=0; i < supportedAttributes.length;i++){
if(blackBerryContact.ATTR_WORK == supportedAttributes[i]){
Dialog.alert("updating Work"); // This alert is shown
Dialog.alert("is supported "+ pimList.isSupportedAttribute(BlackBerryContact.TEL, supportedAttributes[i])+" "+pimList.getAttributeLabel(supportedAttributes[i])); // shows true and work
String wtel = blackBerryContact.getString(BlackBerryContact.TEL, supportedAttributes[i]); // I get a IndexOutOfBounds Exception here
if(wtel != ""){
pimItem.removeValue(BlackBerryContact.TEL, supportedAttributes[i]);
}
pimItem.addString(Contact.TEL, BlackBerryContact.ATTR_WORK, number); // passing the number that has to be updated
if(pimItem.isModified()) {
pimItem.commit();
Dialog.alert("Updated Work Number");
}
}
}
.....
我要更新所有Contact.TEL領域的支持的屬性
Field Values Per Field Supported Attributes
-----------------------------------------------------------------------------
Contact.TEL 8 Contact.ATTR_WORK, Contact.ATTR_HOME,
Contact.ATTR_MOBILE, Contact.ATTR_PAGER,
Contact.ATTR_FAX, Contact.ATTR_OTHER,
Contact.ATTR_HOME2, Contact.ATTR_WORK2
嗨Vivart contact.countValues(BlackBerryContact.TEL)返回用戶當前在他的卡上的聯繫人。例如,如果用戶沒有傳真號碼,則我們無法更新傳真號碼。還要考慮一種情況,用戶沒有任何聯繫號碼,只有名稱,然後contact.countValues(BlackBerryContact.TEL)返回0,代碼將永遠不會進入循環。 我在看什麼是更新用戶的任何聯繫人號碼。 請告知 – Taha 2010-05-13 05:26:45
看我更新的帖子。 – Vivart 2010-05-13 06:44:17
嗨Vivart,你沒有得到我。考慮以下事項 - 聯繫人有8個可能的屬性。目前有2個聯繫人,Contact.ATTR_HOME和Contact.ATTR_WORK當我們說contact.countValues(Contact.TEL);它返回2,因爲聯繫人只有2個號碼。在這裏,我將無法檢查並添加/更新其他nos,因爲它在循環中不可用。我嘗試的邏輯獲取聯繫人的所有支持的屬性變量supportedAttributes具有8個屬性的所有int值也「for循環中的if(blackBerryContact.ATTR_WORK == supportedAttributes [i]){」爲真 – Taha 2010-05-13 11:16:53