Android error during build - "the default public constructor with no argument should be declared." What reason?

Android studio returned an error during the build, even after running Clean and restoring:

A public default constructor with no argument must be declared if a custom constructor is declared.

I could not find the line number or file referenced. I do not know what causes this, since there is no indication in the assembly where and what is the reason for this.

+5
source share
3 answers

If you have your own constructor like this

public class Doge extends RealmObject { public Doge(String name) { ... 

Then you should also have a default constructor without additional parameters.

 public Doge() { // default values possible since 2.0.2 } 
+2
source

Example:

 public class ModelResult { String Ques; String Ans; public String getQues() { return Ques; } public void setQues(String ques) { Ques = ques; } public String getAns() { return Ans; } public void setAns(String ans) { Ans = ans; } public ModelResult(String ques, String ans) { super(); Ques = ques; Ans = ans; } public ModelResult() { super(); // TODO Auto-generated constructor stub } } 

Your missing piece may be

 public ModelResult() { super(); // TODO Auto-generated constructor stub } 
0
source

I searched around and found nothing on the Internet, so I posted this question. I hope he points out to others who are experiencing this in the right direction.

As it turned out, the reason was the new Realm model that I just created, which did not set the default constructor. As soon as this happened, I added a default constructor to the Realm model, and the build error disappeared.

So, check your Realm models for lack of default constructors if you get this error during build!

0
source

Source: https://habr.com/ru/post/1258095/


All Articles