I don’t understand why Eclipse is giving me an error regarding passing the String returned by the BufferedReader into Hashtable’s put(Object,Object) method. I’ve read the API, I don’t recognise any clues. Is it perhaps that it cannot be sure that it will return a unique String?
The String dictionary is set elsewhere in the file,I’ve stripped this down to the bit that matters – the method in question & anything happening with its variables.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Hashtable;
public class Model {
private Hashtable hash=new Hashtable();
private String dictionary;
public void loadWords() throws IOException{
BufferedReader br=null;
try{
br=new BufferedReader(new FileReader(dictionary));
do{
hash.put(br.readLine(), new Node<E>);
}
while(br.readLine()!=null);
}catch(IOException iOE){
System.out.println("Fission mailed");
}
finally{
br.close(); // Closing the buffered reader
}
}
It looks like it’s not problem with key it is problem with value part.
You can not add
new Node<E>this as a Value. It must have specific type likenew Node<String>()ornew Node<Integer>().