このような JavaBean クラスを作成しました。
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;
}
}
次に、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);
}
}
しかし、 .addでこのエラーが発生しています
The method add(Invoice) in the type ArrayList<Invoice> is not applicable for the arguments (String)
私がいる場所が間違っている可能性がありますか?