android – Saving nested objects in firebase-ThrowExceptions

Exception or error:

I’m using Firebase as my database for my Android project. In this project, I have Event object, contains mCalendar object which is a date of type “Calendar”.

 mOriginalEvent = new Event(
            id,
            rawTitle.isEmpty() ? null : rawTitle,
            mCalendar,
            mColor,
            mIsCompleteCheckBox.isChecked()
    );

I tried this but it does not works.

FirebaseDatabase.getInstance().getReference("Events").child(id).setValue(mOriginalEvent);

when I insert events it keeps crashing
So How can I save this data to firebase?

……

    public Event(String id, String title, Calendar date, int color, boolean isCompleted) {
        mID = id;
        mTitle = title;
        mDate = date;
        mColor = color;
        this.isCompleted = isCompleted;
    }

    public String getID() {
        return mID;
    }

    public String getTitle() {
        return mTitle;
    }

    public Calendar getDate() {
        return mDate;
    }

    public int getColor() {
        return mColor;
    }

    public boolean isCompleted() {
        return isCompleted;
    }

    protected Event(Parcel in) {
        mID = in.readString();
        mTitle = in.readString();
        mColor = in.readInt();
        mDate = (Calendar) in.readSerializable();
        isCompleted = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mID);
        dest.writeString(mTitle);
        dest.writeInt(mColor);
        dest.writeSerializable(mDate);
        dest.writeByte((byte) (isCompleted ? 1 : 0));

    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<Event> CREATOR = new Creator<Event>() {
        @Override
        public Event createFromParcel(Parcel in) {
            return new Event(in);
        }

        @Override
        public Event[] newArray(int size) {
            return new Event[size];
        }
    };
}

…………………

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *