Null Pointer Exception

I'm getting a null pointer exception at eitherfor(int i=0;i < word.length(); i++)in add ordict1.add(line); in main below and have no idea why I am getting it. Any thoughts?

publicvoid add(String line)

{

String key ="";

String word = line;

for(int i=0;i < word.length(); i++)

{

if(word.charAt(i)=='a' || word.charAt(i)=='b' || word.charAt(i)=='c' )

key = key +'2';

if(word.charAt(i)=='d' || word.charAt(i)=='e' || word.charAt(i)=='f' )

key = key +'3';

if(word.charAt(i)=='g' || word.charAt(i)=='h' || word.charAt(i)=='i' )

key = key +'4';

if(word.charAt(i)=='j' || word.charAt(i)=='k' || word.charAt(i)=='l' )

key = key +'5';

if(word.charAt(i)=='m' || word.charAt(i)=='n' || word.charAt(i)=='o' )

key = key +'6';

if(word.charAt(i)=='p' || word.charAt(i)=='q' || word.charAt(i)=='r' || word.charAt(i) =='s')

key = key +'7';

if(word.charAt(i)=='t' || word.charAt(i)=='u' || word.charAt(i)=='v' )

key = key +'8';

if(word.charAt(i)=='w' || word.charAt(i)=='x' || word.charAt(i)=='y' || word.charAt(i)=='z' )

key = key +'9';

}

if(dict.containsKey(key))

{

List<String> values = this.get(key);

values.add(word);

this.put(key, values);

}

else

{

List<String> values =new ArrayList<String>();

values.add(word);

this.put(key, values);

}

}

publicstaticvoid main (String[] args)

{

Dictionary1 dict1 =new Dictionary1();

try

{

FileReader input =new FileReader(args[0]);

BufferedReader bufRead =new BufferedReader(input);

int setnum = 0;

String line;

line = bufRead.readLine();

while(line!=null)

{

while(line!="#")

{

dict1.add(line);

line = bufRead.readLine();

}

line = bufRead.readLine();

while(line!="#")

{

setnum++;

List<String> keyvals = dict1.parse(line);

dict1.printLine(keyvals, setnum);

line = bufRead.readLine();

//parseline

}

line = bufRead.readLine();

}

bufRead.close ();

}

catch (IOException e)

{

System.out.println ("IO exception =" + e );

}

}

}

[4902 byte] By [thaddeusj113a] at [2007-11-27 6:32:11]
# 1
Not sure if this is the problem (i doubt it).// change thisline!="#"//to! "#".equals(line)
floundera at 2007-7-12 17:57:28 > top of Java-index,Java Essentials,New To Java...
# 2
I'm pretty sure that because you call bufRead.readLine() in your while loop and not while(bufRead.readLine() != null), line is already equal to null when the loop ends. Then it gets passed into run() and causes that exception
snoboardera at 2007-7-12 17:57:28 > top of Java-index,Java Essentials,New To Java...
# 3
Why all the "line = bufRead.readLine();" statements and then not use the information stored in the line variable? Is the program supposed to trhow away all this data?
petes1234a at 2007-7-12 17:57:28 > top of Java-index,Java Essentials,New To Java...
# 4
I got it working. Thanks for the suggestions guys
thaddeusj113a at 2007-7-12 17:57:28 > top of Java-index,Java Essentials,New To Java...