public Graph(String graphFile) throws IOException {
int u, v;
int e, wgt;
Node t;
Scanner sc = new Scanner(new File(graphFile));
String graphType = sc.next();
boolean undirected = true;
if (graphType.equals("directed")) {
undirected = false;
}
FileReader fr = new FileReader(graphFile);
BufferedReader reader = new BufferedReader(fr);
String splits = " +"; // multiple whitespace as delimiter
String line = reader.readLine();
String[] parts = line.split(splits);
System.out.println("Parts[] = " + parts[0] + " " + parts[1]); // THE ERROR IS THIS LINE
V = Integer.parseInt(parts[0]);
E = Integer.parseInt(parts[1]);
}
public class PrimLists {
public static void main(String[] args) throws IOException {
int s = 2;
Scanner sc = new Scanner(System.in);
System.out.println("enter graph input file name:");
String file = sc.nextLine();
Graph g = new Graph(file); // THE ERROR IS THIS LINE
//Graph g = new Graph(fname);
g.display();
}
}
上の文字列を分割しようとすると、私は私がこれであるテキストファイルのグラフで読んでいます、次のエラーに複数のスペース
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at Graph.<init>(PrimLists.java:170)
at PrimLists.main(PrimLists.java:315)
を得続ける:
9
A
B
C
D
E
F
G
H
I
A B 1
B C 2
C E 7
E G 1
G H 8
F H 3
F D 4
D E 5
I F 9
I A 3
A D 1
誰もがなぜ知っていますこれは動作していないと私を助けることができる?おそらく問題は、あなたの文字列リテラル" +"
が含まれていないということです
String splits = "\\s+"; // multiple whitespace as delimiter
の適切な正規表現を意味
String splits = " +"; // multiple whitespace as delimiter
あなたの質問は、現在の状態では少し難解です。コードをデバッグするためのヘルプを求めるのではなく、正確に質問が何であるかを明確にすることができれば役に立ちます。 [これらのガイドライン](http://stackoverflow.com/help/how-to-ask)でもいくつかのアドバイスをチェックすることができます。 – Strikeskids