簡體   English   中英

LazyList.decorate-InstantiateFactory:構造函數必須存在並且是公共異常

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM