我創建了一個像這樣的JavaBean類。無法將Bean添加到ArrayList
package beans;
public class Invoice {
private String companyName;
private double price;
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
然後我創建了一個Servlet,其中從HTML文件中獲取參數,創建了一個Bean。我正在嘗試將該Bean添加到ArrayList。
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String companyName = request.getParameter("txtCompany");
double price = Double.parseDouble(request.getParameter("txtPrice"));
ArrayList<Invoice> list = (ArrayList<Invoice>) new ArrayList();
Invoice r = new Invoice();
r.setCompanyName(companyName);
list.add(r.getCompanyName());
r.setPrice(price);
}
}
但我混得此錯誤。新增
The method add(Invoice) in the type ArrayList<Invoice> is not applicable for the arguments (String)
在哪裏我可能是錯的?