Home arrow static arrow Java Programming [Archive] - Catch Exception in EventDispatch Thread
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Catch Exception in EventDispatch Thread
This topic has 16 replies on 2 pages.    1 | 2 | Next »

Posts:1,995
Registered: 12/10/00
Catch Exception in EventDispatch Thread  
May 30, 2003 4:11 AM



 
Hallo all,

Description:
I sometimes get uncaught exceptions in the EventDispatch thread where none of my components is mentioned.
For example I get the exception given below and in all my subclasses of DefaultListCellRenderer I have a try-catch before call to
super.getListCellRendererComponent(...).
In DefaultListCellRenderer line 80 is: setComponentOrientation(list.getComponentOrientation());
Seems list is null?

The gui freezes and is not resized properly.

When I pass over the same code with debugger in JBuilder the exception does not appear/possibly it has time to repaint properly?/

Question:
1. Can I catch the exceptions thrown in another thread from my thread/specifically the other thread beinf the EventDispatchThread/.

or
2. How can I find out which the "guilty" component is if none of my components is not in the stack dump?
/Non-overridden functions belong to the superclass/

Output:


...
at javax.swing.DefaultListCellRenderer.getListCellRendererComponent(DefaultListCellRenderer.java:80)
at javax.swing.plaf.basic.BasicComboBoxUI.getDisplaySize(BasicComboBoxUI.java:1280)
at javax.swing.plaf.basic.BasicComboBoxUI.getMinimumSize(BasicComboBoxUI.java:965)
at javax.swing.plaf.basic.BasicComboBoxUI.getPreferredSize(BasicComboBoxUI.java:955)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1272)
at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:892)
at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:806)
at java.awt.GridBagLayout.preferredLayoutSize(GridBagLayout.java:630)
at java.awt.Container.preferredSize(Container.java:1175)
at java.awt.Container.getPreferredSize(Container.java:1159)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1274)
at java.awt.BorderLayout.layoutContainer(BorderLayout.java:660)
at java.awt.Container.layout(Container.java:1017)
at java.awt.Container.doLayout(Container.java:1007)
at java.awt.Container.validateTree(Container.java:1089)
at java.awt.Container.validateTree(Container.java:1096)
at java.awt.Container.validateTree(Container.java:1096)
at java.awt.Container.validate(Container.java:1064)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
...


Thanks in advance
Mike
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 4:25 AM (reply 1 of 16)



 
Let's put some Dukes...
 

Posts:203
Registered: 3/27/02
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 4:59 AM (reply 2 of 16)



 
Output:
...
at
javax.swing.DefaultListCellRenderer.getListCellRendere
Component(DefaultListCellRenderer.java:80)

What exception are you getting? Is it a NullPointerException?

What is that ... at the start of the stack trace? That is the important information. Please post that piece.
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 5:07 AM (reply 3 of 16)



 
oops, missed it when copying, yes it is a
java.lang.NullPointerException
as you guessed
 

Posts:203
Registered: 3/27/02
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 5:16 AM (reply 4 of 16)



 
If I get a NullPointerException at this line
setComponentOrientation(list.getComponentOrientation());
naturally I would suspect that list is null. Try a
System.out.println(list);
before that line.
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 5:30 AM (reply 5 of 16)



 
In a JDK class?
In the debugger it seems to be null but that is not exactly my question.
I want to find out where the null list comes from, and which component it belongs to
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
May 30, 2003 8:25 AM (reply 6 of 16)



 
A little raise of the reward...
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:10 AM (reply 7 of 16)



 
Is my question so stupid that I did not even deserve geting flamed? Or the reason is in the weekend?
To be more specific about the question it is enough for me to catch those exceptions at any level, they just must not appear in console.

Thanks in advance
Mike
 

Posts:4,000
Registered: 24.02.01
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:18 AM (reply 8 of 16)



 
Could you narrow your example (ie make it as small as possible, but still get the exception) and post it?

Kind regards,
  Levi
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:38 AM (reply 9 of 16)



 
No, Levi, I don't think if I decompose it I will get it. It is a relatively complex application and I don't believe that I will manage to reproduce exception if application is smaller. As I said it depends on time because it does not happen even the same number of times in several runs of a same build (varies 0..3 for the moment). If you can give some other idea I will appreciate it.

Thanks
Mike
 

Posts:4,000
Registered: 24.02.01
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:40 AM (reply 10 of 16)



 
I'm afraid I can't help you without code. Normally I would recommend debugging, but you have already done that.

I'm sorry,
  Levi
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:45 AM (reply 11 of 16)



 
OK, Levi
Will the others get angry if I give the dukes to you(they are lost anyway for me and besides you helped me in another post with no dukes?)

Mike
 

Posts:203
Registered: 3/27/02
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 1:59 AM (reply 12 of 16)



 
Sorry, I had to leave this thread coz of the weekend. As levi said, its very difficult to find out without seeing the actual source code. If you are 100% sure that your code is not the culprit, why dont you try in another platform (with a different JRE, perhaps)?

Will the others get angry if I give the dukes to
you(they are lost anyway for me and besides you helped
me in another post with no dukes?)

I don't mind you giving dukes to levi. AFAIK he is a nice fellow. :-)

Raghu
 

Posts:1,995
Registered: 12/10/00
Re: Catch Exception in EventDispatch Thread  
Jun 2, 2003 2:09 AM (reply 13 of 16)



 
And also he has to support his expensive 2000/200 enterprise ;)

Thanks all
Mike
 

Posts:8
Registered: 10/13/97
Re: Catch Exception in EventDispatch Thread  
Aug 1, 2003 1:34 PM (reply 14 of 16)



 
My post probably comes too late for you. But anyway let me try it.

You can catch any exception thrown out from the AWT event dispatch thread. What you need to do is this:

Step 1: register a handler class in your main().

System.setProperty
("sun.awt.exception.handler",
"YourHandler");

Step 2: implement your handler class.

public class YourHandler
{
public void handle(Throwable thrown)
{
// eat the exception without dumping
// to the console.
}
}

Hope this helps.

Rich
 
This topic has 16 replies on 2 pages.    1 | 2 | Next »