EMF 中的 NS URI 是什么?
我使用 EMF 生成了一些类,现在我想实例化它们。我创建了与模型和元模型关联的 xmi 文件。现在我想将模型作为实例加载到程序中,但它不断抛出 NullPointerException。
我的代码是:
Map<String,Object> registry = EPackage.Registry.INSTANCE;
String workflowURI = ExcelEditorPackage.eNS_URI;
System.out.println(workflowURI);
ExcelEditorPackage wfPackage = (ExcelEditorPackage) registry.get(workflowURI); //throw NPE here
ExcelEditorFactory wfFactory = wfPackage.getExcelEditorFactory();
Page workflow = wfFactory.createPage();
它在 wfFactory 处抛出一个异常,因为 wfPackage 为空。我的 NS URI 是“http://www.sg/model”(该 URL 不存在)。
I generated some classes using EMF and now I want to instantiate them. I've created the xmi files associated with the model and metamodel. Now I want to load the model as an instance in my program, but it keeps throwing a NullPointerException.
My code is:
Map<String,Object> registry = EPackage.Registry.INSTANCE;
String workflowURI = ExcelEditorPackage.eNS_URI;
System.out.println(workflowURI);
ExcelEditorPackage wfPackage = (ExcelEditorPackage) registry.get(workflowURI); //throw NPE here
ExcelEditorFactory wfFactory = wfPackage.getExcelEditorFactory();
Page workflow = wfFactory.createPage();
It throws an at wfFactory because wfPackage is null. My NS URI is "http://www.sg/model" (this URL does not exist).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NS URI 表示命名空间 URI。这相当于 java 中的包的 xml。显然 EMF 运行时无法加载与您指定的 URI 关联的包。检查您指定的 URI 是否正确。
NS URI means namespace URI. That is the xml equivalent of packages in java. Apparently EMF runtime is unable to load the package associated with the URI you have specified. Check if URI you are specifying is correct.
如果 NPE 确实在您指示的行处抛出,则它不可能发生,因为
wfPackage
为null
。事实上,它必须表明registry
为null
。那应该没关系。 NS URI 只是一个“唯一名称”,表示模型的 XML 命名空间。它不一定是可以解决的。
If the NPE is really thrown at the line you indicate, it cannot be happening because
wfPackage
isnull
. In fact, it must indicate thatregistry
isnull
.That shouldn't matter. The NS URI is just a "unique name" that denotes the XML Namespace for your model. It doesn't have to be resolvable.