Streaming Graph to Gephi using toolkit : NullPointerException

梦想的初衷 提交于 2019-12-14 04:00:02

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/23641359/streaming-graph-to-gephi-using-toolkit-nullpointerexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!