IPath path; //has some path
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
IWorkbenchPage page; //get current active page
try {
IJavaElement sourceJavaElement = JavaCore.create(file);
ITextEditor editor = (ITextEditor)JavaUI.openInEditor(sourceJavaElement); //illegal argument exception here
} catch (PartInitException | JavaModelException e1) {
e1.printStackTrace();
}
我正在使用此代码来打开编辑器,但是当在sourceJavaElement上调用openInEditor时,它会给出非法的参数异常。