×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    5

    Problem appending to List

    Hi,

    I'm facing a problem while using append method in a List extended class. Here's the code:
    Code:
        public void updateList(){
            deleteAll();
            int sz = categorias.size();
            if (sz == 0) return;
            String s = "";
            String dt = "";
            String vl = "";
            Calendar c = Calendar.getInstance();
            Date d = new Date();
            Double db;
            for (int i = 0; i < sz; i++){
                d = (Date)ultima_data.elementAt(i);
                db = new Double(((Double)peso.elementAt(i)).doubleValue()*100);
                c.setTime(d);
                dt = String.valueOf(c.get(Calendar.DAY_OF_MONTH)) + "/" + String.valueOf(c.get(Calendar.MONTH)+1) + "/" + String.valueOf(c.get(Calendar.YEAR));
                vl = Long.toString(db.longValue());
    
                s = categorias.elementAt(i) + " - ";
                s = s + dt + " - ";
                s = s + vl;
                this.insert(i, dt, null);
                append(s, null);
            }
        }
    It runs fine at the emulator (The Micro Edition SDK 3.0 one).
    But when I try to run it in the device (E71), an IndexOutOfBoundsException is thrown at the append method. Here's the complete exception stack trace:

    Code:
    java.lang.IndexOutOfBoundsException
            at javax.microedition.lcdui.ChoiceComponent.checkIndexInBounds(ChoiceComponent.java:172)
            at javax.microedition.lcdui.ChoiceComponent.Insert(ChoiceComponent.java:94)
            at javax.microedition.lcdui.List.Insert(List.java:97)
            at javax.microedition.lcdui.List.append(List.java:82)
            at despesas.v1_02.Categorias.updateList(), bci=184
            at despesas.v1_02.Categorias.addStringArray(Categorias.java:208)
            at despesas.v1_02.Despesas.readRegister(Despesas.java:119)
            at despesas.v1_02.Despesas.startApp(Despesas.java:56)
            at javax.microedition.midlet.MIDletInvoker.invokeStartApp(MIDletInvoker.java:30)
            at com.symbian.j2me.midp.runtimeV2.Application.startAction(Application.java:458)
            at com.symbian.j2me.midp.runtimeV2.Application.startRequest(Application.java:413)
            at com.symbian.j2me.midp.runtimeV2.Application.event(Application.java:264)
            at com.symbian.j2me.midp.runtimeV2.ApplicationEvent.dispatch(ApplicationEvent.java:90)
            at com.symbian.j2me.midp.runtimeV2.ApplicationThread.run(ApplicationThread.java:30)
    I wouldn't be surprised if the mistake I'm doing is a stupid one. I'm away from programming a quite while.

    Appreciate your help!

    Rafael

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    5

    Re: Problem appending to List

    Is there anybody out there?

    Sorry for the annoying insistence.

    Best regards,

    Rafael

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Problem appending to List

    I read your original post, but I'm not sure I have much to contribute, other than questions.

    How many iterations of the loop happen, before the exception?

    This looks like a bug in the implementation, probably some interaction between insert() and append(). I'd suggest you organize the the strings you want in the List into a Vector first, then just append() them to the List.

    Graham.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    5

    Re: Problem appending to List

    Hi Graham, thanks for your reply!

    Well, the exception occurs in the first iteraction of the loop.

    I've already organized the String into a Vector, but I removed it because I thought that could help in performance. In the other side I got some clutter in my code ;|

    I think it's an implementation bug also. I've just downloaded the phoneME source codes from Sun to see if I could get a hint of what's happening, but I think their implementation is too much different from Nokia's, as they don't have a ChoiceComponent.java. They make use of a factory pattern for creating Look and Feel components, and one of that is the LFChoiceImpl. Well, unsuccessful try.

    One think is driving me crazy. In the same code I have another List extending class, that do exactly the same thing for construction and for updating the front end List. That one is working!

    Thanks for the post. I'll keep trying and inform you of any updates.

    Thanks!!

    Rafael

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    5

    Re: Problem appending to List

    Hi Graham and others following the post,

    Sorry about the noise. It was all my fault.

    I had a method called size() before I decided to extend List in the mentioned class. Result: the method overrided size() from List and that confused the implementation of List's insert method

    Problem solved!

    Thanks for the opportunity of explaining the problem to you, Graham. That has brought a light to me!

    Thank you all,

    Rafael

Similar Threads

  1. problem in deleting item from list n database
    By lopesrohan1988 in forum Symbian
    Replies: 0
    Last Post: 2009-03-18, 16:40
  2. Problem in displaying available contacts in list
    By dineshshilpi in forum Mobile Java General
    Replies: 2
    Last Post: 2008-05-13, 11:58
  3. Problem with J2ME POLISH using a list
    By josual in forum Mobile Java General
    Replies: 1
    Last Post: 2006-09-21, 00:47
  4. setting list problem
    By ddhungry in forum Symbian
    Replies: 0
    Last Post: 1970-01-01, 02:00
  5. setting list problem
    By ddhungry in forum Symbian User Interface
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×