我正在尝试使用JGraphT
创建星图,但是我写的内容似乎对编译器来说是错误的。我得到的是标有NullPointerException
的行NULL POINTER
。那是为什么?
private static DefaultWeightedEdge edge(int i, int j) {
DefaultWeightedEdge graphEdge = Graph.getEdge(i,j);
return graphEdge;
}
private static int vertex(int i) {
int vertex = VertexArray[i-1];
return vertex;
}
private static void setWeight(DefaultWeightedEdge edge, double weight) {
Graph.setEdgeWeight(edge, weight); //NULL POINTER
}
private static SimpleWeightedGraph<Integer, DefaultWeightedEdge> createWeightedGraph() {
Graph = new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);
for (int i = 0; i < numberOfVertices; i++) {
VertexArray[i] = i+1;
Graph.addVertex(vertex(i+1));
}
for (int i = 1; i <= numberOfEdges; i++) {
DefaultWeightedEdge edge = Graph.addEdge(vertex(1), vertex(i+1));
}
for (int i = 1; i <= numberOfEdges; i++) {
setWeight(edge(1, i), 0.95);} //NULL POINTER
//I would like to start group of threads here
service=Executors.newFixedThreadPool(manNum);
for(int k=0; k < manNum; k++){
ManufacturePattern manPat=new ManufacturePattern(k);
service.submit(manPat);
}
return Graph;
}