我正在尝试获取当前选定项目的路径。我正在使用下面的代码:
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench == null ? null : workbench.getActiveWorkbenchWindow();
IWorkbenchPage activePage = window == null ? null : window.getActivePage();
ISelection selection = activePage.getSelection();
if (selection instanceof TreeSelection) {
List list = ((TreeSelection) selection).toList();
for (Object selectedObject : list) {
String path = ((Project) selectedObject).getFullPath().makeAbsolute().toString();
System.out.println(path);
}
}
但是,当我运行这些东西时,我得到以下异常:
java.lang.ClassCastException: org.eclipse.core.internal.resources.Project cannot be cast to org.eclipse.core.internal.resources.Project
at junitcategories.handlers.SampleHandler.execute(SampleHandler.java:48)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
这是类加载问题吗?我该如何解决?--对不起,我是插件开发的新手。
谢谢, 塔马斯