LazyList.decorate - InstantiateFactory: The constructor must exist and be public exception
I have that code:
public class User
...
private List<Country> countri开发者_开发技巧es = 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;
}
...
In country class:
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;
}
}
When I create a new User object I give this exception:
java.lang.IllegalArgumentException: InstantiateFactory: The constructor must exist and be public
Anyone know why?
Seems like the only constructor you have is:
public Country(int countryId, String countryName)
while the factory expects to find no-arg constructor (common requirement):
public Country()
Add it to your Country
class and you'll be fine.
精彩评论