I want to retrieve contacts from my phone using j2me but i am facing exception in the below code.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ahmad_Faraz
Posted On:   Wednesday, July 6, 2011 07:43 AM

List phone_contact=new List("Phone Contacts",Choice.IMPLICIT); List down = (List)d.getCurrent(); int listindex=down.getSelectedIndex(); try { PIM pim = PIM.getInstance(); PIM.getInstance().listPIMLists(1); String[] names = pim.listPIMLists(PIM.CONTACT_LIST); pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, names[0]); ContactList addressbook = (ContactList) (pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY)); Contact contact = null; String phoneNumber = null; Enumeration items = null; items = addressbook.items(); while (items.hasMoreElements()) { contact = (Contact) items.nextElement(); in   More>>

List phone_contact=new List("Phone Contacts",Choice.IMPLICIT);
List down = (List)d.getCurrent();
int listindex=down.getSelectedIndex();

try
{

PIM pim = PIM.getInstance();
PIM.getInstance().listPIMLists(1);
String[] names = pim.listPIMLists(PIM.CONTACT_LIST);

pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, names[0]);

ContactList addressbook = (ContactList) (pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY));

Contact contact = null;
String phoneNumber = null;

Enumeration items = null;
items = addressbook.items();

while (items.hasMoreElements())
{
contact = (Contact) items.nextElement();
int telCount = contact.countValues(Contact.NAME);

int nameCount = contact.countValues(Contact.FORMATTED_NAME);
if (telCount>0&& nameCount>0)
{

for (int i = 0; i < telCount; i++)
{
phoneNumber = contact.getString(Contact.NAME, i);
}
phone_contact.append(phoneNumber,null);


}
phone_contact.setCommandListener(this);
d.setCurrent(phone_contact);

}



} catch (SecurityException e) {

} catch (Exception e){

}

   <<Less
About | Sitemap | Contact