我对如何实现一些 JUNG 类感到非常困惑。我正在尝试使用“KleinbergSmallWorldGenerator”创建一个图表,但我不太确定如何正确初始化。
我的代码:
Factory<? extends Graph<Integer, Integer>> graph_factory;
Factory<Integer> vertexFactory;
Factory<Integer> edgeFactory;
KleinbergSmallWorldGenerator<Integer,Integer> smallWorld;
public GraphView() {
smallWorld = new KleinbergSmallWorldGenerator<Integer,Integer>(graph_factory, vertexFactory, edgeFactory, 20, 3) ;
Graph2 = smallWorld.create();
}
即使我执行graph_factory.create();,我也会得到“java.lang.NullPointerException”;
帮助我理解;谢谢!
最佳答案
graph_factory
、vertexFactory
和 edgeFactory
在构造时均为 null
。这是由于他们使用 their initial value, per the JLS .
在您的构造函数中,我想您希望传递这些对象的实时实例,而不是在无参数构造函数中初始化它们。
关于java - SmallWorldExample 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20271848/