嗨,我正在使用 JGraphT 构建一个大项目。为此,我使用 JGraphT 中的 Djikstra 类构建了一个返回两组节点之间最短路径的方法。
当我尝试访问路径或其子方法时,我得到 NullPointerException。这表示
path = new DijkstraShortestPath(graph, v, y);
可以,但是
path.getPathLength()
抛出异常。
这是代码:
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();
}
任何线索可能是什么?
这是我的系统:
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)