// as Contact.getString returns an exception is teh field is not set, // provide a secure one private String getString(Contact c, int field, int attr) { try { return c.getString(field, attr); } catch (Exception e) { } return ""; }
private void populateToDoList(String searchTerm) { toDoList.setModel(new DefaultListModel()); try { String[] pimListNames = pim.listPIMLists(PIM.TODO_LIST); for (int i = 0; i < pimListNames.length; ++i) { ContactList cl = (ContactList) pim.openPIMList(PIM.TODO_LIST, PIM.READ_ONLY, pimListNames[i]); Enumeration items = cl.items(searchTerm); while (items.hasMoreElements()) { Contact c = (Contact) items.nextElement(); toDoList.addItem(c.getString(Contact.FORMATTED_NAME, 0)); } } } catch (PIMException ex) { ex.printStackTrace(); } if (toDoList.getModel().getSize() == 0) { toDoList.addItem("No matches"); } }