用户没有定义无参数构造函数 [英] users does not define no argument constructor

查看:33
本文介绍了用户没有定义无参数构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直收到这个错误用户没有定义无参数构造函数.如果你使用 ProGuard,请确保这些构造函数没有被剥离."什么都试过了,不知道为什么会这样.

i kept getting this error "users does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped." Tried everything, no idea why it happen.

public void retrievingUserInfo(){

    databaseUserID.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            //clearing the previous userinfo list
            Users_Info.clear();

            //iterating through all the nodes
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                //getting userinfo
                users userinfo = postSnapshot.getValue(users.class);
                //adding userinfo to the list
                Users_Info.add(userinfo);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

users.class

users.class

@Keep
public class users {

    public String user_id, address, contact, name;

    public users(String user_id, String address, String contact,String name) 
    {}


}

推荐答案

JavaBeans 需要无参数构造函数 存在.

JavaBeans require a no-argument constructor to be present.

当一个 Java 类根本没有构造函数时,编译器会自动添加一个默认的无参数构造函数.在类中定义任何构造函数的那一刻,默认的无参数构造函数就会消失.

When a Java class has no constructors at all, there is a default no-arg constructor automatically added to it by the compiler. The moment you define any constructor in the class, the default no-arg constructor goes away.

在您的代码中,您的 users 类定义了这样一个包含参数的构造函数:

In your code, your users class defines such a constructor that contains arguments:

public users(String user_id, String address, String contact,String name) 
{}

只要该构造函数存在,并且您没有定义无参数构造函数,该类就不会有.

As long as that constructor is present, and you don't define a no-arg constructor, that class will not have one.

要解决此问题,您需要从类中删除该构造函数,或者手动向其添加无参数构造函数:

To resolve this, you either need to remove that constructor from the class, or manually add a no-arg constructor to it:

public users() {}

这篇关于用户没有定义无参数构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆