为什么 ResourcesPlugin.getWorkspace().getRoot() 返回 R/?

Why is ResourcesPlugin.getWorkspace().getRoot() returning R/?

我需要打开 select 文件容器的对话框,但新对话框中的容器列表是空的。我看到问题是 ResourcesPlugin.getWorkspace().getRoot() 正在返回 "R/"。有谁知道为什么?

ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(),ResourcesPlugin.getWorkspace().getRoot(),false,"Select new file container");

if (dialog.open() == ContainerSelectionDialog.OK) 
    {
        Object[] result = dialog.getResult();
        if (result.length == 1) 
        {
            destinationDirectory.setText(((Path) result[0]).toString());
        }
    }

ResourcesPlugin.getWorkspace().getRoot() return 是 IWorkspaceRoot 的实例 - toString() 方法将 return R/。这是正确的。

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

// This will print 'R/' string representation of the workspace root
System.out.println(root);

IPath fullPath = root.getFullPath();

// This will print the file path to the workspace root
System.out.println(fullPath.toOSString());

当您从 Eclipse 中测试插件时,会为测试创建一个新工作区 运行。您需要在该测试工作区中创建项目才能在选择对话框中看到它们。