Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Total number of e-mail addresses conflicts the set maximum in Series 40 (Known Issue)

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): All
Keywords: Contact.countValues(Contact.EMAIL)
Created: User:Technical writer 1 (25 Feb 2009)
Last edited: hamishwillee (31 Jul 2013)



Contact.countValues(Contact.EMAIL) returns more e-mail values than the set maximum for the EMAIL field in Series 40.


Starting from Series 40 3rd Edition, Feature Pack 1, the Series 40 implementation of the File Connection and PIM API (JSR-75) conforms to the Mobile Service Architecture Specification (JSR-248) which mandates that the ContactList field EMAIL must support at least 2 e-mail address values per contact. To conform to this requirement in Series 40, 2 e-mail addresses per contact is set as the maximum; if the field includes more than 2 e-mail addresses, IndexOutOfBoundsException will be thrown for the extra values when enumerating them.

Using PIMList.maxValues(Contact.EMAIL) it is possible to check the maximum number of data values that EMAIL field supports in the contact list, which in Series 40 is 2 as described above. In addition, Contact.countValues(Contact.EMAIL) returns the number of data values set in the EMAIL field: in the defined Series 40 Editions this total can exceed the maximum value returned by PIMList.maxValues(Contact.EMAIL). This can be considered illogical behaviour since the values which exceed the defined maximum will not be returned but IndexOutOfBoundsException will be thrown.

How to reproduce

  1. Browse for the native Phonebook application (Menu > Contacts) using a Series 40 device.
  2. Insert a new contact to the native Phonebook application.
  3. Insert e-mail for the new contact (Options > Add detail > E-mail address >) and insert an e-mail address into the text field. Repeat this step by adding at least two more e-mail addresses.
  4. Implement the test MIDlet by using the following code:

 import java.util.Enumeration;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import javax.microedition.pim.*;
public class EmailAddressTest extends MIDlet implements CommandListener {
private Form form;
private Display display;
private Command exitCommand;
private Command searchCommand;
public EmailAddressTest() {
form = new Form("Email Address Test");
searchCommand = new Command("Search", Command.OK, 0);
exitCommand = new Command("Exit", Command.EXIT, 1);
display = Display.getDisplay(this);
public void commandAction(Command cmd, Displayable displayable) {
if (cmd == exitCommand) {
} else if (cmd == searchCommand) {
try {
} catch (PIMException ex) {
/* Search the added contact, return the maximum number of data
values that EMAIL field supports on the list, count the total
number of data values set in the EMAIL field. */

private void searchContact() throws PIMException {
PIM pim = PIM.getInstance();
Enumeration en = list.items();
Contact contact;
int countMax=0;
int count=0;
while (en.hasMoreElements()) {
contact = (Contact) en.nextElement();
countMax = list.maxValues(Contact.EMAIL);
count = contact.countValues(Contact.EMAIL);
for (int index = 0; index < count; index++) {
/* Append "all email values" to Form (including those which
exceed the defined maximum, i.e. all
'IndexOutOfBoundsException' values starting from index 2). */

try {
String value = contact.getString(Contact.EMAIL, index);
} catch (IndexOutOfBoundsException e) {
form.append("ERROR: "+e.toString());
/* Append the defined maximum and total of all email values to Form. */
form.append("MaxValues: "+countMax+"\n");
form.append("CountValues: "+count+"\n");
public void startApp() {}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}

5. Install and launch the test MIDlet and press 'Search'. The MIDlet returns first two e-mail addresses as entered by the user and throws 'ERROR: java.lang.IndexOutofBoundsException' for all the following e-mail addresses.

In addition, the maximum number of data values that EMAIL field supports on the list (2 for Series 40) will be returned together with the total number of data values set in the EMAIL field (which includes all e-mail addresses as entered by the user).


No solution exists.

This page was last modified on 31 July 2013, at 10:11.
27 page views in the last 30 days.