Hi i'm building a big project, using JGraphT. For this I have built a method that returns the shortest path between two sets of nodes, using Djikstra's class from JGraphT.
I get NullPointerException when I try to access path or it's submethods. This means
path = new DijkstraShortestPath(graph, v, y);
is ok, but
path.getPathLength()
throws the Exception.
This is the code:
static GraphPath GraphsDistance(Graph graph, Set<CustomVertex> source, Set<CustomVertex> destination){
//returns the shortest path between 2 sets on nodes
DijkstraShortestPath path,solution;
double distance=Double.MAX_VALUE;
solution=null;
for(CustomVertex v:source){
for(CustomVertex y:destination){
path = new DijkstraShortestPath(graph, v, y);
if (path.getPathLength()<distance){
distance=path.getPathLength();
solution=path;
}
}
}
System.out.println("source: "+source.toString()+ "\ndestination: "+destination.toString());
return solution.getPath();
}
Any clues what can it be?
This is my system:
Product Version: NetBeans IDE 7.0.1 (Build 20121011-unknown-revn)
Java: 1.6.0_27; OpenJDK Client VM 20.0-b12
System: Linux version 3.5.0-17-generic running on i386; UTF-8; en_US (nb)