I have this set of data classes, all in the same file:
@Parcelize data class Response(val RecordView: RecordView):Parcelable
@Parcelize data class RecordView(val Records: List<Records>):Parcelable
@Parcelize data class Gid(val Value: String):Parcelable
@Parcelize data class Features(val Fields: List<Fields>, val FeatureName: String, val Title: String):Parcelable
@Parcelize data class Fields(val Label: String, val Value: String, val FieldName: String, val Features: List<Features>):Parcelable
@Parcelize data class Records(val Gid: Gid, val ImageIds: List<String>, val Fields: List<Fields>, val Features: List<Features>):Parcelable
I then send the Response
object as an intent for the next activity:
val record = intent?.getParcelableExtra<Records>(RECORD)
but the next activity then throws this:
java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.Collection.size()' on a null object reference
at entities.Features.writeToParcel(Features.kt)
at entities.Records.writeToParcel(Records.kt)
at android.os.Parcel.writeParcelable(Parcel.java:1496)
at android.os.Parcel.writeValue(Parcel.java:1402)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:724)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1408)
at android.os.Bundle.writeToParcel(Bundle.java:1157)
at android.os.Parcel.writeBundle(Parcel.java:764)
at android.content.Intent.writeToParcel(Intent.java:8687)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3082)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1518)
at android.app.Activity.startActivityForResult(Activity.java:4225)
This same process works when I just send a more basic class (just Strings in the parameters), using the same @Parcelize
.
And yes, I turned on experimental on my gradle file.
Any ideas? Thanks
I think your API should not response -> Null Object
because data intent can't write Null (write to parcel)
when u use @Parcelize
https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FKT-20032
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With