26

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

@Keep
public class users {

    public String user_id, address, contact, name;

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


}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Old G
  • 366
  • 1
  • 4
  • 9

1 Answers1

37

JavaBeans require a no-argument constructor to be present.

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.

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() {}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • 1
    wow thanks! appreciate it! – Old G Dec 08 '17 at 02:18
  • but by doing this i only retrieve the user ID, and all the data under the user ID such as name, address, etc is not retrieved. – Old G Dec 08 '17 at 02:26
  • Your class member names need to match the names of the children in the database. Or you need to provide getters and setters that match in the JavaBeans fashion. – Doug Stevenson Dec 08 '17 at 02:36
  • { "users" : { "73fsRy0znKRa5zFEl5XsJM4Q7Zf1" : { "address" : "Lokawi", "contact" : "999", "name" : "Logiut" }, "QnHe3Y7LHQXnqrUT85v18PAKhbm1" : { "address" : "Papar", "contact" : "852,525,", "name" : "Bantaton" }, } This is how the json data looks like, i've added another public users() but this time constructor, and the strings is as below: public class users { private String user_id, address, contact, name; still only get the userID. – Old G Dec 08 '17 at 02:53
  • You might want to ask a second well-formatted question explaining this new problem you're running into. – Doug Stevenson Dec 08 '17 at 02:58
  • hey sorry my misytake, its working now, thanks for your help dude – Old G Dec 08 '17 at 03:02