Hand coded EDT violation caused by adding a Button(resource specified) with nativebool = false

85 views
Skip to first unread message

Jeff Crump

unread,
Feb 12, 2014, 11:16:00 AM2/12/14
to codenameone...@googlegroups.com
I have been working on a purely hand coded interface that encapsulates a form. Everything works fine except until I add a button to a container. The button does use the resource I created using the BorderWizard. I couldn't see anything in the discussion groups about this or see any material difference from the KitchSink demo.

Adding the button does not break functionality and everything works as expected. Should I create the form on a background thread?

The following code calls the overridden method for formCreate() which creates a form and populates it when components.

    // Splash form class
    @Override
    protected Form createForm() {
        form = super.createForm();  // parent class method shown below
        Container content = form.getContentPane();
        form.setLayout(new BorderLayout());
        Container container = new Container(new BoxLayout(BoxLayout.Y_AXIS));

        // commenting out this code eliminates the ETD violation *
        button = new Button("Start");
        button.setUIID("Button");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                gotoForm(new Main("/background.png"));
            }
        });
        container.addComponent(button);
        // ----------------------------------------------------- *

        content.addComponent(BorderLayout.CENTER, container);
        return form;
    }

    // Parent class SplashForm
    @Override
    protected Form createForm() {
        form = super.createForm();  // Root class method shown below
        setBackground(fileName);
        return form;
    }
    // Root class RootForm
    protected Form createForm() {
        System.out.println(System.currentTimeMillis() + " RootForm.createForm" + name);
        form = new Form();
        form.setName(name);
        return form;
    }
    //
    // Root class method that invokes createForm()
    //
    public Form showForm() {
        System.out.println(System.currentTimeMillis() + " RootForm.showForm" + name);
        if (form == null) {
            beforeCreate();
            form = createForm();
            afterCreate();
        }
        beforeShow();
        form.show();
        afterShow();
        return form;
    }
1392220548177 RootForm.ConstructorStartup
1392220554677 RootForm.showFormStartup
1392220554677 RootForm.beforeCreateStartup
1392220554677 RootForm.createFormStartup
1392220554692 RootForm.setBackgroundStartup
1392220554708 RootForm.afterCreateStartup
1392220554708 RootForm.beforeShowStartup
1392220554724 RootForm.afterShowStartup   ---> Location Manager invoked 500ms synchronous call
1392220555442 RootForm.ConstructorSplash  ---> location determined
1392220555442 RootForm.gotoFormStartup
1392220555442 RootForm.beforeExitStartup
1392220555442 RootForm.showFormSplash
1392220555442 RootForm.beforeCreateSplash
1392220555442 RootForm.createFormSplash
1392220555442 RootForm.setBackgroundSplash
1392220555474 RootForm.beforeShowSplash
EDT violation detected!

Shai Almog

unread,
Feb 12, 2014, 1:10:21 PM2/12/14
to codenameone...@googlegroups.com
Use the verbose version of the EDT violation detection to get a stack to the specific offending line.

jeffery.s...@gmail.com

unread,
Feb 12, 2014, 1:12:48 PM2/12/14
to codenameone...@googlegroups.com
I was able to trace it further to the call of form.show();

EDT violation detected!
com.codename1.impl.javase.JavaSEPort$EDTViolation: EDT Violation Stack!
 at com.codename1.impl.javase.JavaSEPort.checkEDT(JavaSEPort.java:328)
 at com.codename1.impl.javase.JavaSEPort.getFace(JavaSEPort.java:3752)
 at com.codename1.ui.Font.getFace(Font.java:420)
 at com.codename1.ui.Font.equals(Font.java:494)
 at com.codename1.ui.Form.changeFocusState(Form.java:1641)
 at com.codename1.ui.Form.setFocused(Form.java:1614)
 at com.codename1.ui.Form.initFocused(Form.java:1268)
 at com.codename1.ui.Form.show(Form.java:1299)
 at com.codename1.ui.Form.show(Form.java:1281)
 at com.crumptech.shoppin.mobile.shoppin.forms.RootForm.showForm(RootForm.java:43)
 at com.crumptech.shoppin.mobile.shoppin.forms.RootForm.gotoForm(RootForm.java:165)
 at com.crumptech.shoppin.mobile.shoppin.ui.Startup.showSplash(Startup.java:86)
 at com.crumptech.shoppin.mobile.shoppin.ui.Startup$1.locationUpdated(Startup.java:66)
 at com.codename1.impl.javase.StubLocationManager$1.run(StubLocationManager.java:82)
 at java.util.TimerThread.mainLoop(Timer.java:555)
 at java.util.TimerThread.run(Timer.java:505)


Sent from Windows Mail

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/5whECnym9AQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/eaf1ae30-1673-4efe-84c0-e00d575da9ef%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jeffery.s...@gmail.com

unread,
Feb 12, 2014, 1:48:40 PM2/12/14
to codenameone...@googlegroups.com
I found the problem. The event fired by the LocationManager's location listener was creating the new form. To fix this problem for all callers I placed the method which invokes the next form into a "callSerially".

Sorry for the trouble.


    public void gotoForm(final RootForm nextForm) {
        System.out.println(System.currentTimeMillis() + " RootForm.gotoForm " + "(" + name + ")");
        beforeExit();
        Display.getInstance().callSerially(new Runnable() {
            public void run() {
                nextForm.showForm();
            }
        });
    }




Sent from Windows Mail

From: Shai Almog
Sent: ‎Wednesday‎, ‎February‎ ‎12‎, ‎2014 ‎12‎:‎10‎ ‎PM
To: codenameone...@googlegroups.com

Shai Almog

unread,
Feb 13, 2014, 2:59:26 AM2/13/14
to codenameone...@googlegroups.com
Hi,
its actually a bug in the Java SE port since the location events should be sent on the EDT. We'll fix it for the next update.
Reply all
Reply to author
Forward
0 new messages