Simple iteration and Branch Statement problem

Hi

I am having trouble with the code below which seems to be doing nothing after thefor(int i = 0; i < numberOfRecords; i++ ):

publicstaticvoid sellItems()

{

String itemCode;

Item temp =null;

boolean valid =false;

double amount = 0.0;

System.out.println();

System.out.println("******** Sell item screen ********");

System.out.println();

System.out.print("Enter code for the item to be sold: ");

do

{

itemCode = console.nextLine();

temp =null;

[b]for(int i = 0; i < numberOfRecords; i++ )[/b]

{

if(items[i].getItemCode().equalsIgnoreCase(itemCode))

{

if(items[i]instanceof Fruit)

{

temp = items[i];

System.out.println("Please enter the amount of " +

temp +" you wish to sell");

amount = Double.parseDouble(console.nextLine());

}

elseif(items[i]instanceof Vegetable)

{

temp = items[i];

System.out.println("Please enter the amount of " +

temp +" you wish to sell");

}

}

}

if (temp ==null)

{

System.out.println("Error, item code " + itemCode +

" was not found!");

}

else

{

valid =true;

}

}while (valid !=false);

}

Is anybody able to give me a pointer on why this is happening?

Cheers

CC

[2793 byte] By [cookie_crumblea] at [2007-11-27 4:30:07]
# 1
At quick glance, it seems that i < numberOfRecords is false. Make sure when you instantiate numberOfRecords that the value is what you want it to be.
tk393a at 2007-7-12 9:39:18 > top of Java-index,Java Essentials,Java Programming...
# 2

Thanks

When i Instantiate numberOfRecords = 20;

it compiles and continues through the code but then i get a

Enter code for the item to be sold: BAN01

Exception in thread "main" java.lang.NullPointerException

at GroceryStore.sellItems(GroceryStore.java:163)

at GroceryStore.main(GroceryStore.java:23)

Line 163:

if(items[i].getItemCode().equalsIgnoreCase(itemCode))

Any ideas on this one?

Cheers

CC

cookie_crumblea at 2007-7-12 9:39:18 > top of Java-index,Java Essentials,Java Programming...