I'm new to Firebase Database , I just want to save an array of data in a Firebase database. when I try to save it, an error is displayed. Below I mentioned the POJO Class and Logcat error while saving data.
POJO Code Class
@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;
}
}
Data storage
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 delete this public ArrayList<Reviews> reviewsList = new ArrayList<>();reviewList in the POJO Class, the data stored in the Firebsae database is excellent.
Does anyone know help me solve this problem.
Update
I solved this problem in two ways. Offer given by Oleg Osipenko
1) Make the inner class static
2) Moving the inner class to another file.
, .