Easy fix I think

This is the error I get:
Exception in thread "main" java.lang.NullPointerException
at ShoppingCart.AddToCart(ShoppingCart.java:9)
at Shopper.main(Shopper.java:6)
I have this assignment that I have to do. I think I am hung up on syntax
type problems.
Thanks very much.
FIRST FILE:
public class ShoppingCart
private int _itemsInCart;
private String _itemDescription[];
private double _itemPrice[];
void AddToCart (String Item, double Price)
_itemDescription[ _itemsInCart ] = Item;
_itemPrice[ _itemsInCart ] = Price;
void DisplayCart ()
for (int i=0 ;i<itemPrice.length ;i++ )
System.out.println("Item " + ": " + itemDescription[i] + " $" +
itemPrice); //What is it unable to see what itemDescription is?
NEXT FILE:
public class Shopper
public static void main(String[] args)
/* declare the variable with type
instantiate the object using new and the name of the class
ShoppingCart myShoppingCart = new ShoppingCart();
myShoppingCart.AddToCart("Soup", .50);
myShoppingCart.AddToCart("Soup", .90);
myShoppingCart.AddToCart("Milk", 1.50);
myShoppingCart.DisplayCart();

//You forgot to initialize the arrays
private String _itemDescription[];
private double _itemPrice[];it should look like this
private String[] _itemDescription = new String[10];
private double[] _itemPrice = new double[10];

Similar Messages

Maybe you are looking for