Pedro
Pedro

Reputation: 11

how to use PIM lists properly in J2ME?

What is the correct way to check if a PIM string array is supported?

can I use:

if (MyContactList.isSupportedField(Contact.ADDR)){...}

or would I be better to check :

if (MyContactList.isSupportedArrayElement(Contact.ADDR, Contact.ADDR_STREET))

or both?

The following is my problem code:

if (MyContactList.isSupportedField(Contact.ADDR)) {
//...
//...
String[] AaddressLines = CurrentContact.getStringArray(Contact.ADDR, 0);;
}

It doesn't matter if I comment out the "if" block it always crashes. Only fix I can see is to ignore addresses altogether, please help.

Upvotes: 1

Views: 872

Answers (2)

Kulai
Kulai

Reputation: 640

On device I could not get Contact.NAME even though isSupportedField(Contact.NAME) returned true. Then I had to get the individual fields of Contact.NAME by calling

String[] Names = ContactObj.getStringArray(Contact.NAME, 0);

When you concat all elements in Names array, you get Contact name. This worked on all devices.

Upvotes: 0

bharath
bharath

Reputation: 14473

Better way to do like this. Its working fine for me. See this sample,

String[] lists = pim.listPIMLists(PIM.CONTACT_LIST);
ContactList clist =  (ContactList) pim.openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY, lists[index]);
Enumeration contacts = clist.items();
while (contacts.hasMoreElements()) {

Contact c = (Contact) contacts.nextElement(); 
int[] fields = clist.getSupportedFields();
for (int count = 0; count < fields.length; count++) {
int value = fields[count];
// do smething

if (value == Contact.ADDR && c.countValues(Contact.ADDR) > 0) {
String[] addr = c.getStringArray(Contact.ADDR, 0);
...
...
  }
 }
}

Upvotes: 3

Related Questions