Eclipse 插件开发项目中的JavaModelException

Eclipse 插件开发项目中的JavaModelException,eclipse,exception,plugins,model,eclipse-jdt,Eclipse,Exception,Plugins,Model,Eclipse Jdt,我正在开发一些“eclipse插件”,打算提取一些关于源代码中使用的类型的信息。为了实现这一点,我开始使用Eclipse JDT 1) 选择所需的项目: IProject userDesiredProject = workspace.getProject(userDesiredProjectName); IJavaProject userDesiredJavaProject = JavaCore.create(userDesiredProject); 2) 选择所需的源代码文件(类似于foo.

我正在开发一些“eclipse插件”,打算提取一些关于源代码中使用的类型的信息。为了实现这一点,我开始使用Eclipse JDT

1) 选择所需的项目:

IProject userDesiredProject = workspace.getProject(userDesiredProjectName);
IJavaProject userDesiredJavaProject = JavaCore.create(userDesiredProject);
2) 选择所需的源代码文件(类似于
foo.java
):

3-使用包含
foo.java
编译单元的
userDesiredCompilationUnit
,以便使用
getTypes()
方法捕获类型:

IType[] allTypes = null;
try
{
    allTypes = userDesiredCompilationUnit.getAllTypes();

    //CODE STUCKS HERE AND "JavaModelException" OCCURS.

}
catch (JavaModelException e)
{
    //TODO Auto-generated catch block
    e.printStackTrace();
}
但在执行上述代码时,会发生
JavaModelException
。需要注意的是,我已经测试了
userDesiredCompilationUnit
,它包含了正确的对象

请帮帮我。
非常感谢。

堆栈跟踪显示了什么?@greg-449:Solved!!它显示没有找到用于此源代码的java模型。我重新创建了该项目并解决了问题。:-)非常感谢greg。
IType[] allTypes = null;
try
{
    allTypes = userDesiredCompilationUnit.getAllTypes();

    //CODE STUCKS HERE AND "JavaModelException" OCCURS.

}
catch (JavaModelException e)
{
    //TODO Auto-generated catch block
    e.printStackTrace();
}