org.eclipse.swt.SWTException: "Widget is disposed" from table refresh

24,665

Solution 1

Seems like refresh() method is called after the viewer is disposed (closed?). You can avoid this exception by checking:

public void refresh() {
   if (viewer != null && !viewer.getControl().isDisposed()) {
      // Actual refresh code
   }
}

Solution 2

Try use display.isDisposed() like this.

    shell.getDisplay().asyncExec(new Runnable()
    {
        @Override
        public void run ()
        {
            if(!display.isDisposed() && !disposing)
            {
                              //you source code
            }
        }
    });

But remember that isDisposed() return true then disposing end. Thats why you shod use flag

disposing = true;

display.dispose();

disposing = false;

Solution 3

Just create a new work-space. Import your projects. It worked for me. :)

Share:
24,665
Alb
Author by

Alb

Updated on August 24, 2020

Comments

  • Alb
    Alb over 3 years

    The app is an Eclipse 3.6 based RCP (so jface version 3.5.2) running on windows 7.

    I have a custom View class that contains a TableViewer and calls refresh() on it. Sometimes, but not very often it results in the stack trace below. It's called from within the UI thread. I suspected the problem was with other code that changes the backing list to the table, but that any code that does this is also run in either a syncExec or asyncExec method so I don't understand how it could be a synchronisation issue between the changing of table items and the refresh of the viewer.

    Any ideas what i can do to prevent this happening?

    !ENTRY org.eclipse.jface 4 2 2010-10-20 09:22:06.140 !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jface". !STACK 0 org.eclipse.swt.SWTException: Widget is disposed 
    at org.eclipse.swt.SWT.error(SWT.java:3884) at org.eclipse.swt.SWT.error(SWT.java:3799) 
    at org.eclipse.swt.SWT.error(SWT.java:3770) at org.eclipse.swt.widgets.Widget.error(Widget.java:463) 
    at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:336) 
    at org.eclipse.swt.widgets.Widget.getData(Widget.java:521) 
    at org.eclipse.jface.viewers.AbstractTableViewer.setSelectionToWidget(AbstractTableViewer.java:921) 
    at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:1711) 
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1399) 
    at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1353) 
    at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1455) 
    at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537) 
    at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1414)
    ... 
    at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:179)
    
  • Jan Hruby
    Jan Hruby over 11 years
    it is just a workaround, which you would have to use basically everywhere. This error is thrown, if some disposed widgets are not garbage collected, I got this error very often when widget has been used as listener somewhere and it was not unregistered after being disposed of. The solution proposed by spektom only avoids the problem on one place, not actually fix it, I would use it as a last instance. First I would check, if your widget is referenced somewhere after it is disposed of.