Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException at java.lang.Object.notify(Native Method)

Alba

What I'm trying to do:

Launch a window to request parameters

What I've tried:

  1. If I remove the vp.wait(), the window disappears.
  2. If I remove notify(), the program doesn`t wait.

Here's my code:

public static void main(String[] args) throws InterruptedException{
    if(args.length==0){
        ParamsWind vp = new ParamsWind();
        vp.setVisible(true);
        synchronized (vp){
             try {
                vp.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
 .....


public class ParamsWind extends JDialog {
  ...
  public ParamsWind() 
    ....
       //Create Ok Button and program Action Listener
    Button ok = new Button("OK");
    ...
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) { 

            if(f.getText().equals("") || r.getText().equals("")){
                ErrorWind verr = new ErrorWind();
                verr.setVisible(true);
            }
            notify();
Jon Skeet

Well here's the problem, in actionPerformed.

notify();

You're doing that without a synchronized block, so the thread doesn't own the monitor for this... hence the exception.

However, you don't just want a synchronized block, because you're actually calling notify() on the wrong object. You want to use the ParamsWind:

synchronized(ParamsWind.this) {
    ParamsWind.this.notify();
}

It's not clear to me that using wait() and notify() is really what you want here - or that you won't end up with a race condition - but those are the immediate problems with what you're doing.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is this: Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError?

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException [NetBeans]

From Dev

Exception in "AWT-EventQueue-0" java.lang.NullPointerException

From Dev

Matlab reports "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

From Dev

Chaibi JAVA "AWT-EventQueue-0" java.lang.NumberFormatException: multiple points

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException if-statement

From Dev

working with Threads "AWT-EventQueue-0" java.lang.IllegalStateException

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JButton

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "11101110110100011110111011010001"

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in basic Java GUI interest calculator

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Login form error

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JTable$1 cannot be cast to javax.swing.table.DefaultTableModel

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException For Loops

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException (Panel displays before fully loaded?)

From Dev

NetBeans Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: DSA

From Dev

Exception in "AWT-EventQueue-0" java.lang.NullPointerException

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 8

From Dev

java parseint - Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to university.pojo.Schedule

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 100

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException and JTable problems

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in GUI?

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "FALSE"

From Dev

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException and how to fix it?

From Dev

Java error in my code Exception in thread "AWT-EventQueue-0"

From Dev

Jframe Error: Exception: "AWT-EventQueue-0" java.lang.NullPointerException

Related Related

  1. 1

    What is this: Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError?

  2. 2

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException [NetBeans]

  3. 3

    Exception in "AWT-EventQueue-0" java.lang.NullPointerException

  4. 4

    Matlab reports "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"

  5. 5

    Chaibi JAVA "AWT-EventQueue-0" java.lang.NumberFormatException: multiple points

  6. 6

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException if-statement

  7. 7

    working with Threads "AWT-EventQueue-0" java.lang.IllegalStateException

  8. 8

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JButton

  9. 9

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "11101110110100011110111011010001"

  10. 10

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in basic Java GUI interest calculator

  11. 11

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Login form error

  12. 12

    Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.put(Ljava/lang/Object;)V

  13. 13

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JTable$1 cannot be cast to javax.swing.table.DefaultTableModel

  14. 14

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException For Loops

  15. 15

    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract

  16. 16

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException

  17. 17

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException (Panel displays before fully loaded?)

  18. 18

    NetBeans Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: DSA

  19. 19

    Exception in "AWT-EventQueue-0" java.lang.NullPointerException

  20. 20

    Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 8

  21. 21

    java parseint - Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""

  22. 22

    Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to university.pojo.Schedule

  23. 23

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 100

  24. 24

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException and JTable problems

  25. 25

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException in GUI?

  26. 26

    Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "FALSE"

  27. 27

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException and how to fix it?

  28. 28

    Java error in my code Exception in thread "AWT-EventQueue-0"

  29. 29

    Jframe Error: Exception: "AWT-EventQueue-0" java.lang.NullPointerException

HotTag

Archive