Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从IResourceChangeListener刷新项目_Java_Eclipse - Fatal编程技术网

Java 从IResourceChangeListener刷新项目

Java 从IResourceChangeListener刷新项目,java,eclipse,Java,Eclipse,我已经实现了IResourceChangeListener,以跟踪在eclipse中对我的项目所做的更改。一旦触发更改,我将采取一些操作并刷新项目,代码如下。当执行此代码时,我得到一个异常(代码后面)。是否有方法检查某些内容(资源是否已锁定)并在执行刷新之前等待一段时间 try { ResourcesPlugin.getWorkspace().getRoot().getProject(projectName) .refreshLocal(IResource.DEPTH_I

我已经实现了
IResourceChangeListener
,以跟踪在eclipse中对我的项目所做的更改。一旦触发更改,我将采取一些操作并刷新项目,代码如下。当执行此代码时,我得到一个异常(代码后面)。是否有方法检查某些内容(资源是否已锁定)并在执行刷新之前等待一段时间

try {
    ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)
        .refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (final CoreException ex) {
    ex.printStackTrace();
} catch (final Exception ex) {
    ex.printStackTrace();
}

org.eclipse.core.runtime.AssertionFailedException: assertion failed: The workspace tree is already locked
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.internal.resources.Workspace.setTreeLocked(Workspace.java:2416)
at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:278)
at org.eclipse.core.internal.events.NotificationManager.handleEvent(NotificationManager.java:267)
at org.eclipse.core.internal.resources.Workspace.broadcastEvent(Workspace.java:390)
at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1662)
at org.fastcode.util.SourceUtil.refreshProject(SourceUtil.java:4843)
at org.fastcode.util.FastCodeResourceChangeListener$1.onSuccess(FastCodeResourceChangeListener.java:198)
at org.fastcode.util.FastCodeResourceChangeListener$3.run(FastCodeResourceChangeListener.java:355)
at org.eclipse.ui.internal.UILockListener.doPendingWork(UILockListener.java:164)
at org.eclipse.ui.internal.UISynchronizer$3.run(UISynchronizer.java:158)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1029)
at org.eclipse.ui.dialogs.WizardNewFolderMainPage.createNewFolder(WizardNewFolderMainPage.java:506)
at org.eclipse.ui.wizards.newresource.BasicNewFolderResourceWizard.performFinish(BasicNewFolderResourceWizard.java:92)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:827)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:432)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ui.internal.actions.NewWizardShortcutAction.run(NewWizardShortcutAction.java:135)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)

资源更改通知是由工作区的更改引起的;在收到通知的过程中,无法对工作区进行更改。如果你真的需要,你可以安排一份工作(),但这听起来好像你在做一些不应该做的事情