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 );
}
}
}

