Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.glorb.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail From: Thomas Jensen Subject: [J2ME] List and Font -- again Newsgroups: comp.lang.java.help User-Agent: Pan/0.133 (House of Butterflies) Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Date: 29 Sep 2011 07:09:01 GMT Lines: 147 Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 212.10.67.237 X-Trace: news.sunsite.dk DXC=U?oN_Dh:QbNMG4[9BMmA=KYSB=nbEKnkKJ:BbKlQ?o@L]?9VaEG:?oO[PCN\k>j^5K[>lM@FmEa9@j>hU6ETl1QE>\WF1TVDa1OKm`ON8lceLC X-Complaints-To: staff@sunsite.dk Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:1156 I have included a fully working example below. Basically, it shows that if I use setFont on elements in a list, and then append another element to the list, it throws an ArrayIndexOutOfBoundsException. If I delete some or all the elements, I can add up to the same number of elements as there were when I used setFont first time. Please remember, this is J2ME code, setFont() is a method to List. http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/ List.html To me, this looks like a bug. In the code below, I can succesfully use setFont on elements already in the list, but appending a new element to the list throws an exception. Not using setFont on the new element, but just adding a new element to the list throws an exception. If I do not use setFont there are - of course - no problems in appending elements to a list. Any ideas how to get around it? Do I really have to delete the list and create a new one if I want to add new elements to the list? -- CODE START -- import java.util.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class listtest extends MIDlet implements CommandListener { private Display display; private List list; private Command exitcmd, reloadcmd; private Vector v; Font f; public void startApp() { reloadcmd = new Command("Reload", Command.SCREEN, 1); exitcmd = new Command("Exit", Command.EXIT, 2); f = Font.getFont(0, 0, Font.SIZE_LARGE); v = new Vector(1,1); v.addElement("string1"); v.addElement("string2"); v.addElement("string3"); v.addElement("string4"); list = new List("", Choice.IMPLICIT); list.addCommand(reloadcmd); list.addCommand(exitcmd); list.setCommandListener(this); int i = 0; for (Enumeration e = v.elements(); e.hasMoreElements(); i++ ) { list.append((String)e.nextElement(), null); // ArrayIndexOutOfBoundsException, if setting font here... // list.setFont(i, f); } for (i=1 ; i