I just want to know how to read and write the ArrayList. I use Kotlin.
data class CustomerTxn(
@field:SerializedName("txn_note")
val txnNote: String? = null,
@field:SerializedName("txn_date")
val txnDate: String? = null,
@field:SerializedName("amount")
val amount: String? = null,
@field:SerializedName("txn_type")
val txnType: String? = null,
@field:SerializedName("contact")
val contact: String? = null,
@field:SerializedName("transaction_images")
var transactionImages: ArrayList<String>? = null,
@field:SerializedName("created_at")
val createdAt: String? = null,
@field:SerializedName("cashbook")
val cashbook: String? = null,
@field:SerializedName("view_type")
val viewType: String? = null,
@field:SerializedName("id")
val id: String? = null,
@field:SerializedName("modified_at")
val modifiedAt: String? = null
):Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readArrayList(null),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString(),
parcel.readString()) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(txnNote)
parcel.writeString(txnDate)
parcel.writeString(amount)
parcel.writeString(txnType)
parcel.writeString(contact)
parcel.writeList(transactionImages)
parcel.writeString(createdAt)
parcel.writeString(cashbook)
parcel.writeString(viewType)
parcel.writeString(id)
parcel.writeString(modifiedAt)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<CustomerTxn> {
override fun createFromParcel(parcel: Parcel): CustomerTxn {
return CustomerTxn(parcel)
}
override fun newArray(size: Int): Array<CustomerTxn?> {
return arrayOfNulls(size)
}
}
These lines are giving me error :
parcel.readArrayList(null)
parcel.writeList(transactionImages)
The error for parcel.readArrayList(null) : Type mismatch. Required:ArrayList<String>? Found(ArrayList<Any!>?..ArrayList<*>?)
The error for parcel.writeList(transactionImages) : Java type mismatch expected (Mutable)List<(raw) Any?>! but found ArrayList<String>?. Use explicit cast
I'm using Java instead of Kotlin but I think this problem can handled by a same solution.
I often use: