NoSuchMethodError using @Parcelize Annotation in Kotlin
Asked Answered
M

1

6

I'm currently trying out the experimental (which might be why it's not working...) @Parcelize annotation to generate Parcelable code. Most types seem to be working fine, but I'm having issues with Serializables throwing a NoSuchMethodError:

   10-05 13:55:18.549 20808-20808/com.app E/AndroidRuntime: FATAL EXCEPTION: main
   Process: com.app, PID: 20808
   java.lang.NoSuchMethodError: No virtual method writeSerializable(Ljava/util/Date;)V in class Landroid/os/Parcel;
   or its super classes (declaration of 'android.os.Parcel' appears in /system/framework/framework.jar)
       at com.app.models.Job.writeToParcel(Job.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)
       at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:65)
       at android.app.Activity.startActivityForResult(Activity.java:4183)
       at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:711)
       at android.app.Activity.startActivity(Activity.java:4522)
       at android.app.Activity.startActivity(Activity.java:4490)

I know I could fix this by changing the Date objects to Strings, but would rather not. Has anyone else run into this issue that could provide a viable workaround other than using Strings?

If needed, here's the implementation for reference:

@Parcelize
data class Job(val id: String,
               val description: String,
               val state: String,
               val job_type: String?,
               val close_on: Date?,
               val posted_on: Date?) : Parcelable
Macmullin answered 5/10, 2017 at 18:5 Comment(2)
Which Kotlin version are you using?Pronate
1.1.4, which was my issue after futher research.Macmullin
M
7

Didn't find anything on SO, so rather than deleting I'll leave it here for reference incase anyone else runs into it. It looks like this has been logged as a bug that affects 1.1.4 and 1.1.50. (I was using 1.1.4).

Looks like it's been fixed for versions 1.1.6 and above.

Macmullin answered 5/10, 2017 at 18:24 Comment(1)
Still have this issue. How did you fix it? 1.1.6 doesn't seem to be available yet.Crotchety

© 2022 - 2024 — McMap. All rights reserved.