[英]Streaming Graph to Gephi using toolkit : NullPointerException
我正在嘗試創建一個普通圖,並使用Gephi工具包將其流式傳輸到Gephi GUI。 我正在關注工具包和流插件教程。 我很難使我的代碼正常工作,因為查找API未返回有效值。 在調試時,我發現下面的兩個Lookup方法都返回空值,因此我在使用這些對象訪問其他方法時遇到了麻煩。
StreamingServer服務器= Lookup.getDefault()。lookup(StreamingServer.class);
ServerControllerFactory controllerFactory = Lookup.getDefault()。lookup(ServerControllerFactory.class);
由於“服務器”或“ controllerFactory”均為空,因此使用“服務器”或“ 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);
解決此問題的任何輸入都將有所幫助。
如果無法訪問gephi工具包的META-inf/services
文件夾,則會發生這種情況; 例如,當您合並罐子時; 等,尤其是在嘗試進行服務器端部署時。
ps類文件在那里; 因此不會拋出Class Not Found異常; 但是無法找到服務; 有關更多信息,請參見http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.