使用工具包将流图传送给Gephi:NullPointerException [英] Streaming Graph to Gephi using toolkit : NullPointerException
问题描述
我试图创建一个正常的图形,并使用Gephi工具包将其传输到Gephi GUI。我正在关注该工具包和流式插件教程。
我的代码无法工作,因为查找API没有返回有效的值。在调试时,我可以发现下面的两种查找方法都返回空值,因为我在使用这些对象访问其他方法时遇到问题。
StreamingServer server = 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);
这是我的代码:
//初始化一个工程 - 因此工作区
ProjectController pc = Lookup.getDefault()。lookup(ProjectController.class);
pc.newProject();
工作区工作区= pc.getCurrentWorkspace();
//获取图形实例
GraphController graphController = Lookup.getDefault()。lookup(GraphController.class);
GraphModel graphModel = graphController.getModel();
Graph graph = graphModel.getGraph();
//添加样本图结构数据
节点n1;
节点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
文件夹不可访问,则可能发生这种情况;例如当你合并罐子;等等,当你尝试做服务器端部署时特别常见。
p.s。类文件在那里;所以不会引发Class Not Found异常;但服务无法找到;欲了解更多信息,请参阅 http://docs.oracle.com /javase/7/docs/api/java/util/ServiceLoader.html
I'm trying to create a normal graph and stream it to Gephi GUI using the Gephi toolkit. I am following the the toolkit and the streaming plugin tutorials. I am having difficulty getting my code to work because the lookup API is not returning valid values. On debug, I could find that both the Lookup methods below return null values because of which I am having trouble in accessing other methods using these objects.
StreamingServer server = Lookup.getDefault().lookup(StreamingServer.class);
ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);
As both 'server' or 'controllerFactory' are null, accessing any methods using 'server' or 'controllerFactory' objects would then throw NullPointerException. For example, at :
ServerController serverController = controllerFactory.createServerController(graph); server.register(serverController, context);
This is the code I have:
//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);
Any inputs to solve this would be helpful.
This could happen if META-inf/services
folder of gephi toolkit is not accessible; e.g. when you merge jars; etc. especially common when you try to do server side deployment.
p.s. The class files are there; so no Class Not Found exception is thrown; but services are not being able to be located; for more info see http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html
这篇关于使用工具包将流图传送给Gephi:NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!