对于ShoppingCart类型,方法clear()未定义 [英] The method clear() is undefined for the type ShoppingCart

查看:306
本文介绍了对于ShoppingCart类型,方法clear()未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过JSP实现一个购物网站。我有一个名为 ShoppingCart 的Java对象和一个名为Item的对象。在 ShoppingCart 中,有一个包含Item对象的向量。我的想法是当我调用 addItem()方法时,我使用: -

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);

确保ShoppingCart已宣布已经: -

ensuring that the ShoppingCart has already been declared:-

ShoppingCart cart = new ShoppingCart("file_path_to_file"); 

以及 addItem 的内容是: -

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();  
}  

其中items是向量。这很好用绝对。但是,我现在创建了一个名为clear的新方法: -

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();  
}  

saveMe方法只保存到一个Object文件: -

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();  
}  

当我使用以下方式调用clear方法时: -

When I call the clear method using:-

cart.clear();

我收到错误消息: -

I get the error message:-


jsp文件中的行:108发生错误:/project/cart.jsp
类型ShoppingCart未定义方法clear()

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.

有点像样具有一点体面的服务器插件的IDE将顺便自动完成。

A bit decent IDE with a bit decent server plugin will do that automagically by the way.

这篇关于对于ShoppingCart类型,方法clear()未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆