View Single Post
Old 01-25-2005, 05:16 PM   #1 (permalink)
BoltedDown
Crazy
 
[JAVA] java.lang.NullPointerException

Ok guys, i've got some new code ready for ya...

Code:
java.lang.NullPointerException
	at restaurant1model.ProductCatalog.getSpecification(ProductCatalog.java:36)
	at restaurant1model.Register.enterItem(Register.java:54)
	at restaurant1view.Program1.main(Program1.java:54)
Code:
	public ProductSpecification getSpecification(String itemCode)
	{
		ProductSpecification item = null;
		boolean foundFlag = false;
		//System.out.println(itemCode);
		for (int i = 0; i < productSpecifications.length && !foundFlag; i++)				//for (int i = 0;!(i >= productSpecifications.length || foundFlag);	i++)		
		{
			if (itemCode.equals(productSpecifications[i].getItemId()))
			{
				item = productSpecifications[i];
				foundFlag = true;
			}
		}
		return item;
	}
Code:
	public boolean enterItem(String upc, int quantity)
	{
		boolean flag = false;
		if (sale == null || sale.isComplete())
		{
			sale = new Sale();
		}
		ProductSpecification productionSpecification;
		productionSpecification =
			(ProductSpecification) productCatalog.getSpecification(upc);
		if (productionSpecification != null)
		{
			flag = sale.makeLineItem(productionSpecification, quantity);
		}
		else
		{
			flag = false;
		}
		return flag;
	}
Code:
case 1 : // Event 1 - Enter Item
	{
		boolean doSaleAgain;
		do
		{
		int tableNumber = Program1.readInt("Enter Table Number");
		String itemCode = JOptionPane.showInputDialog("Enter Item Code", "X00");
		int quantity = Program1.readInt("Enter Quantity");
		register.enterItem(itemCode, quantity);
		doSaleAgain =
		readBoolean("Do you wish to enter another item?");
	}
	while (doSaleAgain);
	doAgain = true;
	break;
}
The bottom three snippets are all assosciated with their respective parts of the original error message (top). Let me know what you want to know and I will do my best to answer.

Thank you all very much!!

-BoltedDown
BoltedDown is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62