I Know this might not be what you might be expecting, but
I never thought you could (null).addElement(..), add elemets to a null
object.
in the contructor, why dont you do this,
listOfItems = new Vector();
ITH
Amit
> -----Original Message-----
> From: SUBSCRIBE JSP-INTEREST Lam [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, December 15, 1999 5:49 AM
> To: [EMAIL PROTECTED]
> Subject: Shopping Cart: What is the problem here?
>
> Hi:
>
> I'm trying to put together a simple Shopping Cart, but get an error along
> the lines of:
>
> Exception in jsp:
> javax.servlet.ServletException at
> org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextI
> mpl.java:367) at
> _0005cbasket_0002ejspbasket_jsp_0._jspService(_0005cbasket...
>
> What is the problem here - what's the business with PageContext? - and how
> do I resolve it? Thanks in advance if you're taking the time to look at
> this. Here's what my code basically looks like (I've highlighted the
> offending line).
>
> First, I have shop.jsp which sets up an object of type ShoppingCart:
>
> if (session.getValue("ShoppingCart") == null)
> {
> ShoppingCart cart = new ShoppingCart();
> session.putValue("ShoppingCart", cart);
> }
>
> Then I have basket.jsp which attempts to add an item of type ShoppingItem
>
> ShoppingItem aShoppingItem = new ShoppingItem(selectedItem);
> ShoppingCart cart = (ShoppingCart) session.getValue("ShoppingCart");
> cart.AddItem(aShoppingItem); // offending line!
> session.putValue("ShoppingCart", cart);
>
>
> basket.jsp is where I get the error in page compilation.
> Here are my two class definitions:
>
> package extra;
>
> import java.util.*;
>
> public class ShoppingCart
> {
> Vector listOfItems;
>
> public ShoppingCart()
> {
> listOfItems = null;
> }
>
> public void AddItem(ShoppingItem anItem)
> {
> listOfItems.addElement(anItem);
> }
> }
>
> package extra;
>
> public class ShoppingItem
> {
> private String itemName;
>
> public ShoppingItem()
> {
> itemName = null;
> }
>
> public ShoppingItem (String anItemName)
> {
> itemName = anItemName;
> }
> }
>
> ==========================================================================
> =
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> FAQs on JSP can be found at:
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html