Form that is not always executed.

29 views
Skip to first unread message

rdvg...@gmail.com

unread,
Sep 25, 2018, 10:16:39 PM9/25/18
to CodenameOne Discussions
Hi,

I have a method that triggers a form that does not always run. The form has a Timer class to control the time it appears and disappears. In addition to this, for some time the warning was displayed in the debug console (Ljava / util / ArrayList; Z) V 'formTotals

My code:

    private void formaTotales(ArrayList aCompra2, boolean comparacion) {
        double sub1 = 0d;
        double sub2 = 0d;
        double imp1 = 0d;
        double imp2 = 0d;
        double tot1 = 0d;
        double tot2 = 0d;
        int cnLista = 0;
        int cnCompra = 0;
        try {
            for (int i = 0; i < aCompra2.size(); i++) {
                Compra2 cP2 = (Compra2) aCompra2.get(i);
                double tmp1 = 0d;
                double tmp2 = 0d;
                if (comparacion) {
                    tmp1 = cP2.getCantidad() * cP2.getPrecioComparacion();
                } else {
                    cnLista++;
                    tmp1 = cP2.getCantidad() * cP2.getPrecio();
                    if (cP2.getIncluir() == 1) {
                        tmp2 = cP2.getCantidad() * cP2.getPrecio();
                        cnCompra++;
                    }
                }
                sub1 = sub1 + tmp1;
                sub2 = sub2 + tmp2;
                if (cP2.getImpuesto() == 1) {
                    imp1 = imp1 + tmp1 * iU.getImpuesto1();
                    imp1 = imp1 + tmp1 * iU.getImpuesto2();
                    imp2 = imp2 + tmp2 * iU.getImpuesto1();
                    imp2 = imp2 + tmp2 * iU.getImpuesto2();
                }
            }
            tot1 = sub1 + imp1;
            tot2 = sub2 + imp2;
            String tt = idioma.getTotal() + ": 0.00";
            if (tot1 > 0d) {
                tt = idioma.getTotal() + ":   " + redondear(tot1, 2);
                if (tot2 > 0d) {
                    tt = idioma.getTotal() + ":   " + redondear(tot2, 2) + " / " + redondear(tot1, 2);
                }
            }

            Label lbSub = new Label(idioma.getSubTotal() + ":   ");
            Label lbImp = new Label(idioma.getImpuesto() + ":   ");
            Label lbTot = new Label(idioma.getTotal() + ":   ");
            Label lbComprado = new Label(idioma.getComprado());
            Label lbLista = new Label(idioma.getEnLista());
            Label lbcComprado = new Label("(" + cnCompra + ")");
            Label lbcLista = new Label("(" + cnLista + ")");

            lbSub.setUIID("MultiLine2");
            lbImp.setUIID("MultiLine2");
            lbTot.setUIID("MultiLine2");
            lbComprado.setUIID("MultiLine2");
            lbLista.setUIID("MultiLine2");

            Label lbS1 = new Label(redondear(sub1, 2));
            Label lbI1 = new Label(redondear(imp1, 2));
            Label lbT1 = new Label(redondear(tot1, 2));
            Label lbS2 = new Label(redondear(sub2, 2));
            Label lbI2 = new Label(redondear(imp2, 2));
            Label lbT2 = new Label(redondear(tot2, 2));

            lbS1.setUIID("LabelItemBig");
            lbI1.setUIID("LabelItemBig");
            lbT1.setUIID("LabelItemBig");
            lbS2.setUIID("LabelItemBig");
            lbI2.setUIID("LabelItemBig");
            lbT2.setUIID("LabelItemBig");
            lbcLista.setUIID("MultiLine2");
            lbcComprado.setUIID("MultiLine2");

            Container cnL = new Container(new GridLayout(5, 1)).add(new Label("")).add(lbSub).add(lbImp).add(lbTot).add(new Label(""));
            Container cn1 = new Container(new GridLayout(5, 1)).add(lbLista).add(lbS1).add(lbI1).add(lbT1).add(lbcLista);
            Container cn2 = new Container(new GridLayout(5, 1)).add(lbComprado).add(lbS2).add(lbI2).add(lbT2).add(lbcComprado);
            Container cnT = new Container();

            if (tot2 > 0d) {
                cnT.setLayout(new GridLayout(1, 3));
                cnT.add(cnL);
                cnT.add(cn2);
                cnT.add(cn1);
            } else {
                cnT.setLayout(new GridLayout(1, 2));
                cnT.add(cnL);
                cnT.add(cn1);
            }

            Dialog dlg = new Dialog(new BorderLayout());
            dlg.add(BorderLayout.CENTER, cnT);
            dlg.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, true, 500));

            UITimer timer = new UITimer(() -> {
                dlg.dispose();
            });
            timer.schedule(3000, false, dlg);
            dlg.show((Display.getInstance().getDisplayHeight() / 4) * 3, 0, 0, 0);
        } catch (Exception err) {
            Dialog.show("Error", err.getMessage(), "Continuar", null);
        }
    }

Shai Almog

unread,
Sep 26, 2018, 12:51:12 AM9/26/18
to CodenameOne Discussions
Hi,
dialog is a different form so the timer will stop working as it's bound to the current form.

rdvg...@gmail.com

unread,
Sep 26, 2018, 11:38:02 AM9/26/18
to CodenameOne Discussions
Hi,

Based on your suggestion, delete the Timer (logically the Component Dialo does not disappear after 3 seconds) and the problem continues; that is to say: the form does not always appear.

What could be happening?

Shai Almog

unread,
Sep 27, 2018, 12:15:53 AM9/27/18
to CodenameOne Discussions
Hi,
I didn't make a suggestion. I just made a comment about a piece of code that looked wrong because I can't understand the code or the problem.

Dialog.show() is blocking and if you invoked it as part of an event chain that also shows the form then the form won't show.
Reply all
Reply to author
Forward
0 new messages