我使用以下代码在Eclipse Luna中创建一个文件夹。
public static IFolder createFolder(final IPath path) throws CoreException {
final IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
final IContainer parent = folder.getParent();
if (parent instanceof IFolder && !parent.exists()) {
createFolder(parent.getFullPath());
}
folder.create(true, true, null);
return folder;
}
此处路径值类似于/MyProject/resources/myFolder
,资源文件夹已存在。
它抛出异常而不是创建文件夹。但是相同的代码适用于Eclipse Juno。
例外:
org.eclipse.core.internal.resources.ResourceException: The resource tree is locked for modifications.
at org.eclipse.core.internal.resources.WorkManager.checkIn(WorkManager.java:116)
at org.eclipse.core.internal.resources.Workspace.prepareOperation(Workspace.java:2251)
at org.eclipse.core.internal.resources.Folder.create(Folder.java:92)
at org.eclipse.core.internal.resources.Folder.create(Folder.java:125)
.
.
.
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4441)
at org.eclipse.swt.SWT.error(SWT.java:4356)
at org.eclipse.swt.SWT.error(SWT.java:4327)
at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:283)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:274)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:224)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:159)
如何解决我在Eclipse Luna中遇到的上述问题?