NPE with KleinbergSmallWorldGenerator

  • Raymond

    Raymond - 2009-11-14

    Hi, I'm trying to use the KleinbergSmallWorldGenerator to generate a graph, however I run into a NullPointerException when running the code.  Could someone help me with what's wrong?  The exception stack trace is:

        Exception in thread "main" java.lang.NullPointerException
    at edu.uci.ics.jung.algorithms.generators.random.KleinbergSmallWorldGenerator.create(
    at test.SmallWorldTest.main(

    Here's the code I'm using:

        public class SmallWorldTest {

    public static void main(String args) {
    UndirectedSparseGraph.<Number, Number> getFactory();
    KleinbergSmallWorldGenerator<Number, Number> Generator = new KleinbergSmallWorldGenerator<Number, Number>(
    SparseGraph.<Number, Number> getFactory(), new VertexFactory(),
    new EdgeFactory(), 10, 1.6);
    Graph<Number, Number> graph22 = Generator.create();

    private static class VertexFactory implements Factory<Number> {
    int i = 0;

    public Number create() {
    return new Integer(i++);


    private static class EdgeFactory implements Factory<Number> {
    int count = 0;

    public Number create() {
    return new Integer(count++);


  • Anonymous - 2012-08-27


    Did you figure out what's the problem, becuase i am facing the same problem

  • Joshua O'Madadhain

    Salvador, please post your complete stack trace and specify which version of JUNG you're using.  The original problem report doesn't appear to make any sense based on the current code (line 165 doesn't look like a likely place for an NPE).



Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks