简体   繁体   English

LazyList.decorate-InstantiateFactory:构造函数必须存在并且是公共异常

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

I have that code: 我有该代码:

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;
    }
...

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: 当我创建一个新的User对象时,会给出以下异常:

java.lang.IllegalArgumentException: InstantiateFactory: The constructor must exist and be public java.lang.IllegalArgumentException:InstantiateFactory:构造函数必须存在并且是公共的

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. 将其添加到您的Country类别中,您就可以了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为 LazyList Apache commons 找到的装饰方法 - Decorate method on found for LazyList Apache commons 错误:实体和Pojos必须具有可用的公共构造函数。 科特林 - error: Entities and Pojos must have a usable public constructor. Kotlin 如何修复“实体和 Pojo 必须有一个可用的公共构造函数”错误? - How to fix "Entities and Pojos must have a usable public constructor" error? Room Android 实体和 POJO 必须有一个可用的公共构造函数 - Room Android Entities and POJOs must have a usable public constructor 错误:实体和 Pojo 必须有一个可用的公共构造函数 - Java - error: Entities and Pojos must have a usable public constructor - Java 房间持久性:实体和 Pojos 必须有一个可用的公共构造函数 - Room Persistence: Entities and Pojos must have a usable public constructor 子类构造函数 - 为什么子类构造函数必须存在默认构造函数? - Subclass constructors - Why must the default constructor exist for subclass constructors? 默认构造函数无法处理隐式超级构造函数抛出的异常类型 FileNotFoundException。 必须定义一个显式构造函数 - Default constructor cannot handle exception type FileNotFoundException thrown by implicit super constructor. Must define an explicit constructor 默认构造函数无法处理隐式超级构造函数引发的异常类型IOException。 必须定义一个显式构造函数 - Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor 如何模拟构造函数的静态公共类引发异常 - how to mock the constructor an static public class to throw exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM