Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

users does not define no argument constructor [duplicate]

Tags:

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)      {}   } 
like image 343
Marvin Gorres Avatar asked Dec 08 '17 01:12

Marvin Gorres


People also ask

Does not define a no-argument constructor If you are using?

Donor does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.

Which constructor does not take any arguments?

A constructor that takes no parameters is called a parameterless constructor.

Why we use no-arg 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.

What is a no-arg constructor in c++?

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.


1 Answers

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() {} 
like image 200
Doug Stevenson Avatar answered Oct 10 '22 20:10

Doug Stevenson