Search code examples
javajgrapht

getEdge() method returns null for the edge I've just created


I want to acociate some elements in my code (mthing) with the certain edges of the graph, but when I'm trying to get the edge I've just created - I'm getting null. Am I using this method in a wrong way? Do I always have to use method getEdgeSource()? What should I do, if I don't want to pass the whole graph, only one edge?

graph.addEdge(c2, c1);
System.out.println("added connection c2 c1" + graph.getEdge(c2, c1));

MovingThing mthing = new MovingThing(parent, graph.getEdge(c1, c2));    

Just in case: I've extended the DefaultEdge by some methods and extended edge class and code above are in the same package. I have no problems iterating through all edges.


Solution

  • You are probably using directed graph and are creating edge from c2 to c1 but then passing non-existing edge from c1 to c2 hence null into your MovingThing constructor