Hi,

In my app, every time I enter a new record it is placed in automatic form 
at the end of the elements of a container. When I read the database I sort 
the records by date so that the most recent one appears first.
I did not find any method that would allow me to order the elements and 
proceeded to create one assuming that the last included element should move 
to the first position. My problem is that I create a temporary container 
and every time I try to add a new element it sends me an error message that 
it already exists.

"[EDT] 0:0:0,5 - Exception in AppName version 1.0
[EDT] 0:0:0,5 - OS and
[EDT] 0:0:0,5 - Error java.lang.IllegalArgumentException: Component is 
already contained in Container: Container[x=0 y=0 width=1440 height=2050 
name=null, layout = BoxLayout, scrollableX = false, scrollableY = true, 
components = [SwipeableContainer, SwipeableContainer, SwipeableContainer, 
SwipeableContainer, SwipeableContainer, SwipeableContainer, 
SwipeableContainer, SwipeableContainer, SwipeableContainer]]
[EDT] 0:0:0,6 - Current Form null
[EDT] 0:0:0,6 - Exception: java.lang.IllegalArgumentException - Component 
is already contained in Container: Container[x=0 y=0 width=1440 height=2050 
name=null, layout = BoxLayout, scrollableX = false, scrollableY = true, 
components = [SwipeableContainer, SwipeableContainer, SwipeableContainer, 
SwipeableContainer, SwipeableContainer, SwipeableContainer, 
SwipeableContainer, SwipeableContainer, SwipeableContainer]]
at com.codename1.ui.Container.insertComponentAtImpl(Container.java:819)
at com.codename1.ui.Container.insertComponentAt(Container.java:810)
at com.codename1.ui.Container.addComponent(Container.java:732)
at com.codename1.ui.Container.add(Container.java:351)
at 
com.innova507.principal.LiberAbstracto.ordenaContenedorMayorMenor(LiberAbstracto.java:762)
at 
com.innova507.principal.Liber.lambda$formaMantenimientoListaDeseos$23(Liber.java:1219)
at 
com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:349)
at com.codename1.ui.Button.fireActionEvent(Button.java:570)
at com.codename1.ui.Button.released(Button.java:604)
at com.codename1.ui.Button.pointerReleased(Button.java:708)
at com.codename1.ui.Form.pointerReleased(Form.java:3339)
at com.codename1.ui.Component.pointerReleased(Component.java:4528)
at com.codename1.ui.Display.handleEvent(Display.java:2079)
at com.codename1.ui.Display.edtLoopImpl(Display.java:1051)
at com.codename1.ui.Display.mainEDTLoop(Display.java:969)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)"

My code:

    public Container ordenaContenedorMayorMenor(Container cnC) {

        Container cnResp = new Container(BoxLayout.y());
        if (cnC.getComponentCount() > 0) {
            Component cn = (Component) 
cnC.getComponentAt(cnC.getComponentCount() - 1);
            if (cn instanceof SwipeableContainer) {
                cnResp.add(cn);
                for (int i = 0; i < cnC.getComponentCount() - 2; i++) {
                    cnResp.add((SwipeableContainer) cnC.getComponentAt(i));
                }
            }
        } else {
            cnResp = cnC;
        }
        return cnResp;
    }


-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to codenameone-discussions+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/7aaa80a5-dad4-4dcf-9abf-dca28de62188%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to