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) {} }
Donor does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.
A constructor that takes no parameters is called a parameterless constructor.
In Java, a no-argument constructor is the default constructor and if you don't define explicitly in your program. Then Java Compiler will create a default constructor with no arguments. The purpose is to call the superclass constructor.
But if you do type in a constructor within your class, you are not supplied a default constructor by the compiler. A default constructor is always a no-argument constructor, i.e. it accepts no arguments, and that's why it is known as default no-argument constructor.
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() {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With