以下代码来自多个来源,旨在获取EObjects(通常称为EMF)并将其转换为GMF(模型的图形版本)。
//Uses generated factory to make an empty model
CanardModel model = factory.createCanardModel();
//Uses the ViewService class to make a diagram
Diagram diagram = ViewService.createDiagram(model, CanardModelEditPart.MODEL_ID, CanardDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
//Create a resource related to the given URI and add it to the diagram
URI diagUri = URI.createFileURI("output/out.canard");
ResourceSet resourceSet = new ResourceSetImpl();
Resource diagramResource = resourceSet.createResource(diagUri);
diagramResource.getContents().add(diagram);
但是我在第二行代码中遇到以下错误
Exception in thread "main" java.lang.ExceptionInInitializerError
at ca.umontreal.iro.geodes.canard.tool.CanardTool.main(CanardTool.java:77)
Caused by: java.lang.NullPointerException
at org.eclipse.gmf.runtime.diagram.core.internal.DiagramPlugin.getPluginId(DiagramPlugin.java:48)
at org.eclipse.gmf.runtime.diagram.core.services.ViewService.<clinit>(ViewService.java:136)
... 1 more
我尝试了以下方法: