title: How to: Using a custom class as a Map parameter
body: <p>I'm getting the nullpointerexception in the line 9 (the one with a comment).</p>
  
  <p>I'm trying to use the method as a parametre in the shoppingCart class:</p>
  
  <pre><code>import java.util.*;
  
  public class ShoppingCart {
  
      private Map&lt;String, Purchase&gt; ShoppingCart;
  
      public void add (String product, int price) {
          Purchase purchase = new Purchase(product, 1, price);
          ShoppingCart.put(product, purchase);         //this line doesn't work!
      }
  
      public int price() {
          Collection&lt;Purchase&gt; total = shoppingCart.values();
  
          }   
  }
  </code></pre>
  
  <p>The constructor for the Purchase method is: </p>
  
  <pre><code> public Purchase(String product, int amount, int price) {
  </code></pre>
  
  <p>The Main tries to add the product to the shoppingCart which causes the nullpointerexception:</p>
  
  <pre><code>ShoppingCart cart = new ShoppingCart();
  cart.add("milk, 3);
  </code></pre>
  
  <p>I suppose I'm missing something fundamental when it comes to Maps. What am I doing wrong here?</p>