Menu

Null Pointer in ISOMLayout

2012-03-19
2013-05-29
  • Brian Michalk

    Brian Michalk - 2012-03-19

    There is another unanswered thread here that appears to be about the same problem.

    Exception in thread "main" java.lang.NullPointerException
        at edu.uci.ics.jung.algorithms.layout.ISOMLayout.adjustVertex(ISOMLayout.java:176)
        at edu.uci.ics.jung.algorithms.layout.ISOMLayout.adjust(ISOMLayout.java:139)
        at edu.uci.ics.jung.algorithms.layout.ISOMLayout.step(ISOMLayout.java:107)
        at edu.uci.ics.jung.algorithms.layout.LayoutDecorator.step(LayoutDecorator.java:58)
        at edu.uci.ics.jung.visualization.layout.ObservableCachingLayout.step(ObservableCachingLayout.java:59)
        at edu.uci.ics.jung.algorithms.layout.util.VisRunner.prerelax(VisRunner.java:62)
        at edu.uci.ics.jung.visualization.DefaultVisualizationModel.setGraphLayout(DefaultVisualizationModel.java:113)
        at edu.uci.ics.jung.visualization.DefaultVisualizationModel.<init>(DefaultVisualizationModel.java:74)
        at edu.uci.ics.jung.visualization.DefaultVisualizationModel.<init>(DefaultVisualizationModel.java:58)
        at edu.uci.ics.jung.visualization.BasicVisualizationServer.<init>(BasicVisualizationServer.java:139)
        at drawAlert(EricsAnalytics.java:244)
    

    With the offending code:

        public static void drawAlert(DirectedSparseMultigraph<Node, String> g, String caption)
        {
            //The function transform describes how a vertex s should be colored when processed by the drawing algorithm
            Transformer<Node,Paint> vertexColor = new Transformer<Node,Paint>() {     
                public Paint transform(Node s)
                {
                    return s.getColor();
                } 
            }; 
            Transformer<Node,String> stringLabeller = new Transformer<Node,String>() {
                public String transform(Node s)
                {
                    return s.getName();
                }
            };
            Layout<Node, String> layout = new ISOMLayout<Node, String>(g);
            layout.setSize(new Dimension(500,500)); // sets the initial size of the space
            BasicVisualizationServer<Node, String> bvs = new BasicVisualizationServer<Node, String>(layout);
            bvs.setPreferredSize(new Dimension(500,500));
            bvs.getRenderContext().setVertexLabelTransformer(stringLabeller);
            bvs.getRenderContext().setVertexFillPaintTransformer(vertexColor);
            JFrame frame = new JFrame("Simple Graph View");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(bvs);
            frame.pack();
            frame.setVisible(true);
        }
    

    It appears that at this point:

    BasicVisualizationServer<Node, String> bvs = new BasicVisualizationServer<Node, String>(layout);
    

    The error is thrown, and it appears to be a threading problem.  If I change the layout to circle layout, and step through, it will mostly complete.  But ISOMlayout always gives me problems.  I'm trying to draw about 500 nodes.  If I reduce my graph to a few nodes, it sometimes works correctly.

     
  • Anonymous

    Anonymous - 2012-04-10

    I am receiving the same Error. Did anyone come across any solution?

     
  • Jens Einloft

    Jens Einloft - 2012-04-10

    This error occurs in my project every time i try to create the layout with an empty graph (no nodes or edges).
    Other layouts work without this error. I posted it a time ago, but no answer. If you need this layout, you have to fix the ISOMLayout or wait for an update. (Or add a pseudonode to the graph and after creating the BVS, remove him)

     

Log in to post a comment.