this.lexic.add(word);
You are using this in constructor, that means, you are using the object during its creation. That is why you get NPE. remove this, it will work.
if you put filling part in a method also, that means
Set<String> lexic = new TreeSet<String>();
is also in same method, then also "this" will not work because "this" is not for local level variable. But in that case also, it will not give NPE but compiler error.
This code is working fine, you can check once :
public AnagramUserInput()
{
Set<String> result = new TreeSet<String>();
Set<String> lexic = new TreeSet<String>();
File lexicon = new File("output.txt");
BufferedReader br = null;
try{
br = new BufferedReader(new FileReader(lexicon));
String word;
while(((word = br.readLine()) != null)) {
lexic.add(word);//Exception is throwned right in this line
}
}catch(IOException exc) {
System.out.println(exc.toString());
System.exit(1);
}
finally
{
if (br != null)
{
try
{
br.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(lexic);
}
just make sure, file is on proper location as required.