0

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.

My current Firebase Database: enter image description here

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.

enter image description here

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!

Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46
Luke Xuereb
  • 73
  • 12
  • When asking questions on Stack Overflow, please avoid adding screenshots of code and text. Copy the text of code and errors into the question itself so it's easier to read and search. – Doug Stevenson Jan 07 '20 at 19:37
  • try `class Child implements Serializable`. – Martin Zeitler Jan 07 '20 at 19:44
  • @MartinZeitler this did not work... I struggle to understand why you have associated this post with similar questions, as I am yet to find a solution to my problem despite analysing similar questions – Luke Xuereb Jan 09 '20 at 09:38

0 Answers0