I am new to Firebase Database, I just want to Save the array of data in Firebase database. when I am trying to save it shows error. Below I mentioned the POJO Class and Logcat Error while save the data.
POJO Class Coding
@IgnoreExtraProperties
public class StudentReviews {
public String student_name;
public String student_class;
public String student_image;
public String student_section;
public ArrayList<Reviews> reviewsList = new ArrayList<>();
public void StudentReviews() {}
public class Reviews {
public String subject;
public String marks_taken;
public String total_marks;
public String teacher;
}
}
Saving Data
StudentReviews studentReviews = new StudentReviews();
studentReviews.student_name = et_studentName.getText().toString();
studentReviews.student_class = et_student_class.getText().toString();
studentReviews.student_image = "";
studentReviews.student_section = sp_section.getSelectedItem().toString();
studentReviews.reviewsList = reviewsArray;
dbUploadReview.push().setValue(studentReviews); //165th Line in Logcat Error
Logcat Error
com.google.firebase.database.DatabaseException: Invalid key: this$0. Keys must not contain '/', '.', '#', '$', '[', or ']'
at com.google.android.gms.internal.zzbtf.zzjq(Unknown Source)
at com.google.android.gms.internal.zzbtf.zzay(Unknown Source)
at com.google.android.gms.internal.zzbtf.zzay(Unknown Source)
at com.google.android.gms.internal.zzbtf.zzay(Unknown Source)
at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
at com.trending.trendingadmin.fragment.WriteReview.uploadReviews(WriteReview.java:165)
When I remove this public ArrayList<Reviews> reviewsList = new ArrayList<>(); reviewsList in POJO Class data saved in Firebsae database perfectly.
Anyone know help me to solve this issue.
Update
I am Solved this problem by Two Ways. Suggestion given by OlegOsipenko
1) Make the inner class as static
2) Moving the inner class to another file.
Now its work well and good as i expected.
reviewsListvariable to be interfaceListtype instead of specific implementation. And why do you initialise it to the ArrayList instance? Anyway you'll assign to this variable another List object, and you're just performing unnecessary allocations, loading your GC with extra workReviewsclassstaticand run