The import edu. Princeton. Cs. Algs4. In;
The import edu. Princeton. Cs. Algs4. ST.
The import edu. Princeton. Cs. Algs4. StdIn;
The import edu. Princeton. Cs. Algs4. StdOut;
Public class SymbolGraph {
Private ST
Private String [] keys;
Private Graph G;
Public SymbolGraph (String stream, String sp) {
St=new ST
In the In=new In (stream);
While (in) hasNextLine ()) {
String [] a=in the readLine (). The split (sp);
for (int i=0; I & lt; A. ength; I++) {
if (! St. the contains (a) [I]) {
St. put (a [I], st. size ());
}
}
}
Keys=new String (st. size ()];
For (String name: st. keys ()) {
Keys (st. get (name)]=name;
}
G=new Graph (st. size ());
In=new in (stream);
While (in) hasNextLine ()) {
String [] a=in the readLine (). The split (sp);
Int v=st. get (a [0]);
For (int I=1; I & lt; A. ength; I++) {
G.a ddEdge (v, st. get (a [I]));
}
}
}
Public Boolean contains (String s) {
Return st. the contains (s);
}
Public int index (String s) {
Return st. get (s);
}
Public String name (int v) {
Return keys [v];
}
Public Graph G () {
Return G;
}
Public static void main (String [] args) {
The String filename=args [0].
String delim=args [1];
SymbolGraph sg=new SymbolGraph (filename, delim);
Graph G=sg. G ();
While (StdIn. HasNextLine ()) {
String source=StdIn. ReadLine ();
For (int w: G.a DJ (sg) index (source))) {
StdOut. Println (" "+ sg. Name (w));
}
}
}
}
Error:
The Exception in the thread "main" Java. Lang. NullPointerException
At com. Cui. Algorithms. Chapter4_1. SymbolGraph. Index (SymbolGraph. Java: 45)
At com. Cui. Algorithms. Chapter4_1. SymbolGraph. Main (63) SymbolGraph. Java: