I am implementing a shopping website through JSP. I have a Java object called ShoppingCart and one called Item. In ShoppingCart there is a vector which holds Item objects. The idea is when I make a call to the addItem() method, I use:-
cart.addItem(name, image, price, details);
ensuring that the ShoppingCart has already been declared:-
ShoppingCart cart = new ShoppingCart("file_path_to_file");
and the the content of addItem is:-
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 the vector. This works absolutely fine. I have, however, now created a new method called clear:-
public void clear() throws IOException
{
items.clear();
this.saveMe();
}
The saveMe method simply saves to an 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 the error message:-
An error occurred at line: 108 in the jsp file: /project/cart.jsp
The method clear() is undefined for the type ShoppingCart
Can anybody help with any ideas I can try to resolve this issue?
If that method was newly added and you get this error, you’re apparently still using an old version of the class lacking the method in the classpath. You need to save the source code file, recompile/rebuild the class/project, redeploy the project and restart the server to get the new changes to work.
A bit decent IDE with a bit decent server plugin will do that automagically by the way.