I am implementing a JSP shopping site. I have a Java object with a name ShoppingCartand one Item element. There ShoppingCartis a vector containing Item objects. The idea is when I call the method addItem(), I use: -
cart.addItem(name, image, price, details);
ensuring that ShoppingCart is already announced : -
ShoppingCart cart = new ShoppingCart("file_path_to_file");
and contents addItem: -
public void addItem(String name, String image, String price, String detail) throws IOException
{
items.add(new Item(name, image, price, detail));
this.saveMe();
}
where items is a vector. It works great. However, I created a new clear method: -
public void clear() throws IOException
{
items.clear();
this.saveMe();
}
The saveMe method simply saves the Object file: -
private void saveMe() throws IOException
{
FileOutputStream fos = new FileOutputStream(this.filename);
ObjectOutputStream oos = new ObjectOutputStream(fos)
oos.writeObject(this.items);
oos.close();
}
When I call the clear method using: -
cart.clear();
I get an error: -
Error in line: 108 in jsp file: /project/cart.jsp The clear () method is undefined for type ShoppingCart
Can someone help with any ideas I can try to solve this problem?