Inserting elements recursively to List fails in Series 40 6th Edition (Known Issue)
Article Metadata
Tested with
Devices(s): All Series 40, 6th Edition devices
Compatibility
Platform(s): Series 40, 6th Edition
Article
Keywords: List.insert()
Created: User:Kbwiki
(10 Dec 2010)
Last edited: lpvalente
(13 Apr 2012)
Description
Inserting elements recursively (for example by using a for loop) to List by using the method insert(int elementNum, String stringPart, Image imagePart) fails as follows:
- when the number of elements is less than 12, only one element will be shown on the List;
- when the number of elements is 12 or more, the List hangs.
How to reproduce
This issue can be reproduced by using this test MIDlet: File:PopulateList.zip
The MIDlet tests a use case where the number of elements is 12.
After launching the MIDlet, press Populate.
On the affected devices, the MIDlet hangs.
Solution
The method insert(int elementNum, String stringPart, Image imagePart) should not be used to populate a List recursively. If a List needs to be recursively populated with elements, using the method append(String stringPart, Image imagePart) is recommended instead for the purpose.


Incorrect index for the iteration
This is not a bug, rather an error in the provided code. When you iterate in your loop you need to make sure that the index of the element where the insertion is to occur corresponds to the given iteration. This is to ensure that all 13 items are populated by giving a different index to each added item.
Try instead the following code:
if(command.equals(cmdPopulate)) { for(int i=0; i<13; i++) { listPopulate.insert(i, "Populating", null); } }So you need to change:
listPopulate.insert(0, "Populating", null);
to
listPopulate.insert(i, "Populating", null);
Nokia Developer Technical Supportskalogir 11:49, 26 August 2011 (EEST)