Properties Eclipse插件项目首选项保存异常

Properties Eclipse插件项目首选项保存异常,properties,eclipse-plugin,preference,Properties,Eclipse Plugin,Preference,我目前正在开发一个eclipse插件,我创建了自己的属性页,当右键单击所选项目的上下文菜单时将显示该属性页。我试图通过按该页面上的“确定”按钮来保存该页面的值,但我收到异常消息:保存项目首选项时发生异常:/test/.settings/com.example.plugin.prefs.Resource与文件系统不同步:'/test/.settings/com.example.plugin.prefs' 以下是我实施的内容: //Get the project IAdaptable resourc

我目前正在开发一个eclipse插件,我创建了自己的属性页,当右键单击所选项目的上下文菜单时将显示该属性页。我试图通过按该页面上的“确定”按钮来保存该页面的值,但我收到异常消息:保存项目首选项时发生异常:/test/.settings/com.example.plugin.prefs.Resource与文件系统不同步:'/test/.settings/com.example.plugin.prefs'

以下是我实施的内容:

//Get the project
IAdaptable resource = getElement();
if (resource != null) {
   IProject project = (IProject) resource.getAdapter(IProject.class);
}    
//Define project scope
IScopeContext projectScope = new ProjectScope(project);
//Get node by qualified name
Preferences projectNode = projectScope.getNode(MyPlugin.PLUGIN_ID);
//set the value and save it
if (projectNode != null) {
projectNode.put(PROPERTIES_SERVICENAME, serviceName);
}       
try {
projectNode.flush();  // Exception occurs here!!!
} catch (BackingStoreException e) {
e.printStackTrace();
}
据我所知,它还应该在runtime EclipseApplication\test.settings下自动保存一个类似com.example.plugin.prefs的文件,对吗?
有人知道如何解决这个问题吗?

如果在获得该节点后立即执行projectNode.sync怎么办?没有,我尝试过,它不工作,仍然抛出相同的异常…抱歉,我错了,我在刷新之前对projectNode.sync进行了注释,因此肯定不工作,现在它工作正常!非常感谢保罗,非常有帮助的建议!