Build Error in Realm

getting below building code error with Realm

: app: compileDebugJavaWithJavac Note: processing class Error DataBaseQuestion: a public default constructor with no arguments should be declared if a custom constructor is declared. Note. Creating DefaultRealmModule Warning: File for type 'io.realm.DefaultRealmModule' created in the last round is not subject to annotation processing. Warning: a file for the type 'io.realm.DefaultRealmModuleMediator' created in the last round will not be subject to annotation processing. 2 warnings Error: execution failed for task ': app: compileDebugJavaWithJavac'.

Compilation error; see compiler error output for details.

Note. The default constructor is already present in the Model or Java Bean class.

Can someone please help me how to solve this?

DataBaseQuestion.java

public class DataBaseQuestion extends RealmObject{ int id; String Question =null; String QuestionNo =null; List<String> optionList=null; String typeOfQuestion=null; String Answer = null; String Explanation = null; DataBaseQuestion() { } public DataBaseQuestion(int id, String question, String questionNo, List<String> optionList, String typeOfQuestion, String answer, String explanation) { this.id = id; Question = question; QuestionNo = questionNo; this.optionList = optionList; this.typeOfQuestion = typeOfQuestion; Answer = answer; Explanation = explanation; } public String getQuestion() { return Question; } public void setQuestion(String question) { Question = question; } public String getQuestionNo() { return QuestionNo; } public void setQuestionNo(String questionNo) { QuestionNo = questionNo; } public List<String> getOptions() { return optionList; } public void setOptions(List<String> optionList) { this.optionList = optionList; } public String getTypeOfQuestion() { return typeOfQuestion; } public void setTypeOfQuestion(String typeOfQuestion) { this.typeOfQuestion = typeOfQuestion; } public String getAnswer() { return Answer; } public void setAnswer(String answer) { Answer = answer; } public String getExplanation() { return Explanation; } public void setExplanation(String explanation) { Explanation = explanation; } @Override public String toString() { return "DataBaseQuestion{" + "Question='" + Question + '\'' + ", QuestionNo='" + QuestionNo + '\'' + ", options=" + optionList + ", typeOfQuestion='" + typeOfQuestion + '\'' + ", Answer='" + Answer + '\'' + ", Explanation='" + Explanation + '\'' + '}'; } 
+8
java android realm
source share
4 answers

Error: public default constructor with no argument must be declared

You can add the desired default constructor to the specified class and test it.

Change

 DataBaseQuestion() { } 

to

 public DataBaseQuestion() { } 
+9
source share

You forgot the public modifier.

Your program is probably trying to cover it outside the package context, which means that it only looks for public designers. It finds one - one that requires the -args constructor, but does not see the closed package. Adding a "public" access modifier should solve the problem.

 public DataBaseQuestion(){} 

Note. You should look at the lomb in your free time so that you don’t manually handle creating getters, setters, AllArgsContsructors, or NoArgsConstructors

+3
source share

Another possible reason for this error was the definition of a private-private object that inherits from RealmObject.

It fails for the same reason as the above answers: the default constructor is a closed package, so it is not available to the annotation processor. A public class declaration fixed it.

Edit

class DataBaseQuestion extends RealmObject { }

to

public class DataBaseQuestion extends RealmObject { }

+1
source share

Another reason for this may be to declare the class twice by mistake in different packages.

If you define your class:

 public class DataBaseQuestion extends RealmObject { .... } 

And then copy your code to a separate directory

or if it is nested in another class as a static class, then the exact same error may be thrown.

0
source share

All Articles