Connecting Tech Pros Worldwide Forums | Help | Site Map

NullPointerException:null

Newbie
 
Join Date: Apr 2009
Posts: 2
#1: Apr 6 '09
Hi, when I run my code I get a NullPointerException:null. Here is the part of the code where the error occurs:

import java.util.*;
import java.io.*;

public class Decrypt
{
ArrayList<String> dictionary;
ArrayList<String> encryptedText;

public void dictionaryReader() throws IOException
{
try
{
FileReader reader = new FileReader("C:/Dictionary.txt");
Scanner file=new Scanner(reader);
while(file.hasNext())
{
dictionary.add(file.nextLine());
}//while
}//try
catch(IOException exception)
{
System.out.println("**Error**");
System.out.println("The dictionary file has the wrong name or is in the wrong directory.");
System.out.println("Exiting Program");
System.exit(0);
}//catch
}//dictionaryReader
}//Decrypt

The error is at dictionary.add(file.nextLine()); It says:

java.lang.NullPointerException
at Decrypt.dictionaryReader(Decrypt.java:93)
at Decrypt.main(Decrypt.java:24)

NullPointerException:
null

Thanks,
Chris
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Apr 6 '09

re: NullPointerException:null


Most likely you did not initialize your dictionary. Which one is line 93 in your code?
Better yet, just read the NullpointerException article and you should be able to solve the problem.
N002213F's Avatar
Member
 
Join Date: Sep 2007
Location: South Africa
Posts: 37
#3: Apr 6 '09

re: NullPointerException:null


try: Reading and Writing files
Newbie
 
Join Date: Apr 2009
Posts: 2
#4: Apr 6 '09

re: NullPointerException:null


Thank you, the article helped me find the problem with my code.
Reply