开发者

LazyList.decorate - InstantiateFactory: The constructor must exist and be public exception

开发者 https://www.devze.com 2023-02-11 17:25 出处:网络
I have that code: public class User ... private List<Country> countri开发者_开发技巧es = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Country.class));

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消