[ad_1]
My goal is to configure my app so that upon first start, it grabs parcelable “Contact” items from Firebase and loads them into an arraylist.
My contact is defined as follows:
data class Contact(
val contactName: String?,
val contactNumber:Long,
val contactEventList: ArrayList<Event?>
) : Parcelable{
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readLong(),
parcel.readArrayList(Event::class.java.classLoader) as ArrayList<Event?>
)
override fun writeToParcel(parcel:Parcel, flags: Int) {
parcel.writeString(contactName)
parcel.writeLong(contactNumber)
parcel.writeList(contactEventList)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Contact> {
override fun createFromParcel(parcel: Parcel): Contact {
return Contact(parcel)
}
override fun newArray(size: Int): Array<Contact?> {
return arrayOfNulls(size)
}
}
}
And the call to Firebase:
val contactUpdateListener = object: ValueEventListener{
override fun onDataChange(snapshot: DataSnapshot) {
for(postSnapshot in snapshot.children){
val savedContact = postSnapshot.getValue(Contact::class.java)
if (savedContact != null) {
contactList.add(savedContact)
}
}
Log.println(Log.ASSERT, "", "UPDATING CONTACTS")
contactDisplayAdapter.notifyDataSetChanged()
}
override fun onCancelled(error: DatabaseError) {
}
}
dbRef.child("User").child(auth.currentUser?.uid.toString()).child("Contacts").addValueEventListener(contactUpdateListener)
Yet when running the code, I get the error “Class does not define a no-argument constructor.“
I have tried adding constructor():this(){}
to the Contact, but that results in an error message saying “There’s a cycle in the delegation calls chain“
Very new to Android development and still learning OOP in general, couldn’t find much information on this elsewhere, would appreciate any suggestions!
[ad_2]