Null Pointer Exception Error
Hi
I am getting a null pointer exception with the below code:
public static void loadData()
{
int index = 0;
Item temp;
String inputLine;
try
{
BufferedReader br = new BufferedReader (new
FileReader ("grocery.dat"));
inputLine = br.readLine();
while ( index < items.length && inputLine != null)
{
inputLine = br.readLine();
System.out.println(inputLine);
if (inputLine.equals("Fruit")) //3.2 if the "tag" is fruit create an empty fruit item
{
temp = new Fruit(); //call the default fruit constructor to create empty object
System.out.println(temp);
}
else if (inputLine.equals("Vegetable")) //3.2 cont.
temp = new Vegetable();// 3.2 cont
if (temp != null)
{
temp.readAttributes(br); //3.4
items[index] = temp; //3.5
index ++; //3.6
numberOfRecords = index; //3.7
System.out.println(index); //goes up to 7 from file
System.out.println(temp.itemCode);
System.out.println(temp.type);
System.out.println(temp.variety);
}
br.close();//3.8
}
catch (FileNotFoundException e)
{
System.out.println("File grocery.dat was not found");
System.out.println("Error:");
System.out.println(" ");
System.err.print(e);
System.exit(1);
}
catch (IOException e)
{
System.out.println("there was an error reading the file");
}
}
Anybody have any ideas on how to avoid this error?
Cheers
CC.

