[英]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.