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.

[1595 byte] By [cookie_crumblea] at [2007-11-27 3:47:48]
# 1
Post the stacktraceKaj
kajbja at 2007-7-12 8:51:35 > top of Java-index,Java Essentials,Java Programming...
# 2
Along with the NPE, your compiler provided you with a line number. On that line number you are probably invoking a method on an object that has not been initialized (or has become null): hence the NPE.
prometheuzza at 2007-7-12 8:51:35 > top of Java-index,Java Essentials,Java Programming...
# 3
Sorry do you mean this?Exception in thread "main" java.lang.NullPointerExceptionat GroceryStore.loadData(GroceryStore.java:111)at GroceryStore.main(GroceryStore.java:12)CC
cookie_crumblea at 2007-7-12 8:51:35 > top of Java-index,Java Essentials,Java Programming...
# 4
The code compiles OK but when it is run it gives that NPE.CC
cookie_crumblea at 2007-7-12 8:51:35 > top of Java-index,Java Essentials,Java Programming...
# 5

> Sorry do you mean this?

>

>

> Exception in thread "main"

> java.lang.NullPointerException

>at GroceryStore.loadData(GroceryStore.java:111)

> at GroceryStore.main(GroceryStore.java:12)

>

> CC

In the GroceryStore class, on line 111, you are probably calling a method on an object that still points to null.

prometheuzza at 2007-7-12 8:51:35 > top of Java-index,Java Essentials,Java Programming...