[英]LazyList.decorate - InstantiateFactory: The constructor must exist and be public exception
我有該代碼:
public class User
...
private List<Country> countries = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Country.class));
private String country;
...
public void setCountries(List<Country> countries) {
this.countries = countries;
}
public List<Country> getCountries() {
return countries;
}
...
在國家/地區類別中:
public class Country {
private int countryId;
private String countryName;
public Country(int countryId, String countryName)
{
this.countryId = countryId;
this.countryName = countryName;
}
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
}
當我創建一個新的User對象時,會給出以下異常:
java.lang.IllegalArgumentException:InstantiateFactory:構造函數必須存在並且是公共的
有人知道為什么嗎?
似乎您擁有的唯一構造函數是:
public Country(int countryId, String countryName)
而工廠希望找到無參數構造函數(常見要求):
public Country()
將其添加到您的Country
類別中,您就可以了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.