0
これは宿題であり、開始頂点vと終了頂点uの間のパスを見つけようとしています。メソッドをテストするためのテストクラスが提供されましたが、残念ながらNull Pointer Exceptionsが発生しています。DFSグラフのパス探索ヌルポインタの例外を与える
私の方法で明らかなエラーはありますか?
ありがとうございます!
public Iterator<Vertex<V>> returnPath(Graph<V> g, Vertex<V> v, Vertex<V> u){
Iterator<Vertex<V>> result;
Iterator<Edge<V>> it;
Edge<V> e;
Vertex<V> w;
v.setMarker(true);
S.push(v);
if(v.equals(u)){
return S.listIterator();
}
it = v.incidentEdges();
while(it.hasNext()){
e = it.next();
w = g.giveOpposite(v, e);
if(!w.getMarker()){
result = returnPath(g, w, u);
if(result != null){
return result;
}
}
}
S.pop();
return null;
}
public Iterator<Vertex<V>> givePath(Graph<V> g, Vertex<V> v, Vertex<V> u){
S.clear();
return returnPath(g, v, u);
}
スタックトレース:
Exception in thread "main" java.lang.NullPointerException
at TestPath.main(TestPath.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
このステートメントが107の場合:
Iterator<Vertex<Integer>> it = fp.givePath(g,lookup.elementAt(i),lookup.elementAt(j));
if (!it.hasNext()){
投稿Stacktrace – stinepike
@StinePikeが追加されました! – Strobe00
問題はコードの他の部分にあります...このメソッドを呼び出したコードを投稿してください – stinepike