GeeCON Prague 2014*
The moose likes IDEs, Version Control and other tools and the fly likes Invalid thread access Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Invalid thread access Exception" Watch "Invalid thread access Exception" New topic
Author

Invalid thread access Exception

deepak kukreja
Ranch Hand

Joined: Aug 13, 2001
Posts: 54
Hi,
I am making my own Navigator view Plugin for eclipse.
View consists of a TreeViewer.
The issue is I want to refresh(automatic) this view in case of any
addition/deletion/change to the resource workspace.
I refresh my TreeViewer in the code like this:
IResourceChangeListener listener = new MyResourceChangeReporter();
ResourcesPlugin.getWorkspace().addResourceChangeListener(listener);
....

private class MyResourceChangeReporter implements IResourceChangeListener {
public void resourceChanged(IResourceChangeEvent event) {
try{
treeViewer.refresh();
}
catch(Exception e){
e.printStackTrace();
}
}
}
//inner class ends
I am able to add the resources, but while deleting a Project I get exception:
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2119)
at org.eclipse.swt.SWT.error(SWT.java:2051)
at org.eclipse.swt.widgets.Widget.error(Widget.java:370)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:301)
at org.eclipse.swt.widgets.Tree.setSelection(Tree.java:932)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:207)
at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:1123)
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:939)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:695)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:746)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:708)
at com.glic.ea.framework.ide.views.navigator.FrameworkNavigatorView.refresh(FrameworkNavigatorView.java:705)
at com.glic.ea.framework.ide.views.navigator.FrameworkNavigatorView$MyResourceChangeReporter.resourceChanged(FrameworkNavigatorView.java:137)
at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:128)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:839)
at org.eclipse.core.runtime.Platform.run(Platform.java:416)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:143)
at org.eclipse.core.internal.events.NotificationManager.deleting(NotificationManager.java:94)
at org.eclipse.core.internal.resources.Workspace.deleting(Workspace.java:685)
at org.eclipse.core.internal.resources.Resource.delete(Resource.java:440)
at org.eclipse.core.internal.resources.Project.delete(Project.java:290)
at org.eclipse.ui.actions.DeleteResourceAction.delete(DeleteResourceAction.java:284)
at org.eclipse.ui.actions.DeleteResourceAction.delete(DeleteResourceAction.java:271)
at org.eclipse.ui.actions.DeleteResourceAction$2.execute(DeleteResourceAction.java:363)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:64)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1378)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:78)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:98)
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2119)
at org.eclipse.swt.SWT.error(SWT.java:2051)
at org.eclipse.swt.widgets.Widget.error(Widget.java:370)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:301)
at org.eclipse.swt.widgets.Tree.setSelection(Tree.java:932)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:207)
at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:1123)
at org.eclipse.jface.viewers.StructuredViewer.setSelectionToWidget(StructuredViewer.java:939)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:695)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:746)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:708)
at com.glic.ea.framework.ide.views.navigator.FrameworkNavigatorView.refresh(FrameworkNavigatorView.java:705)
at com.glic.ea.framework.ide.views.navigator.FrameworkNavigatorView$MyResourceChangeReporter.resourceChanged(FrameworkNavigatorView.java:137)
at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:128)
at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:839)
at org.eclipse.core.runtime.Platform.run(Platform.java:416)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:143)
at org.eclipse.core.internal.events.NotificationManager.broadcastChanges(NotificationManager.java:67)
at org.eclipse.core.internal.resources.Workspace.broadcastChanges(Workspace.java:133)
at org.eclipse.core.internal.resources.Workspace.endOperation(Workspace.java:753)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1383)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:78)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:98)

Pls give suggestions.
Deepak


Deepak<br />SCJP
Dan Kehn
Dastardly Dan the Author
Ranch Hand

Joined: Jun 11, 2003
Posts: 120
See the SWT FAQ, specifically Why do I get the error "org.eclipse.swt.SWTException: Invalid thread access"?
-- Dan


Co-author of <a href="http://www.jdg2e.com" target="_blank" rel="nofollow">The Java Developer's Guide to Eclipse</a>, 2nd Edition<br />(Yahoo group <a href="http://groups.yahoo.com/group/JDG2E/" target="_blank" rel="nofollow">JDG2E</a>)
 
GeeCON Prague 2014
 
subject: Invalid thread access Exception