I am relatively new to Firebase. I am attempting to programmatically populate the database as can be seen in the below image, which currently consists of a number of members, which each have a String childId and a String name.
I am now trying to add a new field for each member, of type ChildSocialSkills, which is a custom Java object which I created.
The following was done to commit to the database:
ref = FirebaseDatabase.getInstance().getReference().child("Members");
Child child = new Child();
childName = (EditText) findViewById(R.id.childName);
child.setName(childName.getText().toString().trim());
child.setChildId();
//commit to database
ref.child(childName.getText().toString().trim()).setValue(child);
The following is the Child class, which is being populated into the database. As can be seen, whenever a child is created, a new ChildSocialStory is initialised.
public class Child {
private String name;
private String childId;
private ChildSocialStories socialStory;
public Child () {
socialStory = new ChildSocialStories();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setChildId() {
childId = UUID.randomUUID().toString();
}
public String getChildId() {
return childId;
}
public ChildSocialStories getSocialStory() {
return socialStory;
}
For the sake of showing everything, I will show the ChildSocialStoryClass below, which simply consists of a default constructor:
public class ChildSocialStories {
public ChildSocialStories () {
}}
When omitting the ChildSocialStory, all is good and the Member is successfully added to the Firebase Database. Whenever I include the addition of a ChildSocialStory, however, the following error arises each time.
The error is related to the below line of code, which is committing the child to the database (which can also be seen in the last line of the first snippet of code above):
ref.child(childName.getText().toString().trim()).setValue(child);
My aim is to successfully add an object of ChildSocialStories as a child of 'Members' (which will eventually have other children of its own). Is this in any way possible? Any form of assistance would be greatly appreciated.
Thanks in Advance!