我正在尝试使用 Gephi 工具包创建一个普通图形并将其流式传输到 Gephi GUI。我正在关注工具包和流插件教程。我很难让我的代码正常工作,因为查找 API 没有返回有效值。在调试时,我可以发现下面的两个 Lookup 方法都返回空值,因为我无法使用这些对象访问其他方法。
StreamingServer 服务器 = Lookup.getDefault().lookup(StreamingServer.class);
ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);
由于 'server' 或 'controllerFactory' 都为 null,因此使用 'server' 或 'controllerFactory' 对象访问任何方法都会抛出 NullPointerException。例如,在:
ServerController serverController = controllerFactory.createServerController(graph); server.register(serverController, context);
这是我的代码:
//Init a project - and therefore a workspace
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
pc.newProject();
Workspace workspace = pc.getCurrentWorkspace();
// Get the graph instance
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getModel();
Graph graph = graphModel.getGraph();
//Add sample graph structure data
Node n1;
Node n2;
n1 = graphModel.factory().newNode();
n2 = graphModel.factory().newNode();
Edge edge = graphModel.factory().newEdge(n1, n2);
graph.addNode(n1);
graph.addNode(n2);
graph.addEdge(edge);
n1.getNodeData().setLabel("Node 1");
n2.getNodeData().setLabel("Node 2");
edge.getEdgeData().setLabel("Edge 1");
System.out.println(graph.getNodeCount() + " nodes");
System.out.println(graph.getEdgeCount() + " edges");
System.out.println();
StreamingServer server = Lookup.getDefault().lookup(StreamingServer.class);
ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);
ServerController serverController = controllerFactory.createServerController(graph);
String context = "/mycontext";
server.register(serverController, context);
解决此问题的任何输入都会有所帮助。