Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:57:18+00:00 2026-05-26T04:57:18+00:00

I thought I understood EDQ until I hit this problem. I have the code

  • 0

I thought I understood EDQ until I hit this problem. I have the code shown below. It reads from a Bufferred reader. If the first character received is a “Z” I execute one set of code (displaying a JOptionPane) and if it is a 0 I execute another section of code (displaying another JOptionPane). I am trying to do this within the EDQ and so I use SwingUtilities invokeAndWait. When I test these error conditions, the first statement in the conditional works as designed, but I get a java error when testing the else clause. Specifically:

Exception in thread “AWT-EventQueue-2” java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
at java.awt.EventQueue.invokeAndWait(Unknown Source)

It is all part of the same conditional. How can one clause be part of the EDQ and another clause not be.

This is crazy.

Thanks for any help.

Elliott

     while ((line = in.readLine()) != null) {
        if (line.charAt(0) == 'Z') {
            String theMsg;
            theMsg = "No records were found.";
            try {
                SwingUtilities.invokeAndWait(new DoShowDialog(null, theMsg, 0));
            } catch (java.lang.reflect.InvocationTargetException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
            noDocs = true;
            Object args[] = new Object[1];
            args[0] = "1";
            window.call("uploadConfig", args);
            downloadAccount.setEnabled(true);
            uploadAccount.setEnabled(false);
            deleteAllUnselectedCodes.setEnabled(false);
            queue = null;
            if (poll) {
                polltimer.restart();
            }
        } else if (line.charAt(0) == 'O') {
            String theMsg;
            theMsg = "Account is currently checked out 
            by user "+ line.substring(1)
            + ".  You can view this 
            account but you cannot modify it. ";
            try {
                SwingUtilities.invokeAndWait(new DoShowDialog(null, theMsg, 0));
            } catch (java.lang.reflect.InvocationTargetException e1) {
                e1.printStackTrace();
            } catch (InterruptedException e2) {
                // TODO Auto-generated catch block
                e2.printStackTrace();
            }
            initialckBoxState = false;
            accountfoundandnotcheckedout = true;
            viewMode = true;
            patientpane.setEditFields(false);
            otherpane.setEditFields(false);
            getAccountImages(acctEntered); // bluenoble
        }
        .....................
        more stuff
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:57:19+00:00Added an answer on May 26, 2026 at 4:57 am

    Execution doesn’t jump threads.

    Thus all the code posted runs in the EDT (Event Dispatch Thread) and it refuses to invokeAndWait because that causes an inherent deadlock. (Actually, it could be turned into an invoke-immediate as done with SynchronizationContexts in .NET, but it was not designed as such.)

    In this particular case I suspect the code is invoked from within an EDT callback (and copy’n’pasted from another scenario). The “trivial fix” (that would eliminate this exception) would be to eliminate the invokeAndWait methods, but that will have a negative impact if this code is invoked off the EDT as well — the two situations much be handled differently. Take some time to determine when/where this code will run, and why.

    As others have pointed out, this code seems confused: if it’s off the EDT, manipulating Swing objects is bad, and if it’s on the EDT then there is no need to invokeAndWait and blocking is bad.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I understood variable scope until I came across this bit of code:
Thought I understood how classes work, then I tried this code: class user {
I always thought I understood how this works...but lately I have started really using
I thought I understood this but obviously not... I have a method signature like
I thought I understood this junk.... I have an exe compiled to use MFC
I have a question regarding compiling against SDK's, which I thought I understood until
After I thought that I've understood how they work, I tried this: NSString *str1
Ok, so I thought I understood this (no pun intended), but apparently not. var
I have not been working in SQL too long, but I thought I understood
I thought I understood Perl RE to a reasonable extent, but this is puzzling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.