1

我使用annas库作为工具来可视化Collat​​z Conjecture中特定数字序列之间的模式。我正在执行这段代码:

GraphDrawer<BigInteger, DefaultArc<BigInteger>> drawer = new GraphDrawer<BigInteger, DefaultArc<BigInteger>>(graph);
BufferedImage image = new BufferedImage(1000, 1000, BufferedImage.TYPE_3BYTE_BGR);
drawer.draw(image);

它抛出这个错误:

Exception in thread "main" java.lang.NullPointerException
    at annas.graph.drawing.GraphDrawer.draw(GraphDrawer.java:88)
    at Driver.main(Driver.java:36)

安全地假设graph不为空。什么是扔NullPointerException


根据陌生人的要求:

/**
 * Draws the graph
 * 
 * @param buffImage
 *            Image to draw the graph on
 * @return graphical representation of the graph
 */
public BufferedImage draw(BufferedImage buffImage) {
    Map<N, int[]> map = this.placer.place(this.graph, sizeX, sizeY);

    ArrayList<N> nodeSet = this.graph.getNodeMap();
    ArrayList<A> arcSet;
    Graphics2D graphic = buffImage.createGraphics();
    for (N node : nodeSet) {
        arcSet = this.graph.getArc(node);
        this.nodeDrawer.drawNode(graphic, node, map.get(node)[0], map
                .get(node)[1]);
        for (A arc : arcSet) {
            this.arcDrawer.drawArc(graphic, arc, map.get(node)[0], map
                    .get(node)[1], map.get(arc.getHead())[0], map.get(arc
                    .getHead())[1]);
        }
    }
    return buffImage;
}

第 88 行是方法中的第一行(这里map是初始化的)。

4

0 回答 0