android - IllegalStateException: parcel.readString() must not be null -
i put parcelable
object in intent
next activity
:
val intent = intent(mcontext, showtestactivity::class.java) intent.putextra("test", test) log.d("mylog", "${intent.getparcelableextra<test>("test")}") // no problem mcontext.startactivity(intent)
and object in next activity
:
if (!intent.hasextra("test")) throw exception("intent doesn't has 'test' extra") val test: test = intent.getparcelableextra("test")
and here throwing exception:
public open class qbase(): parcelable { ... protected constructor(parcel: parcel?) : this() { parcel?.let { question = parcel.readstring() // parcel.readstring() must not null helptext = parcel.readstring() qvalue = parcel.readdouble() qtype = qtype.valueof(parcel.readstring()) } } override fun writetoparcel(parcel: parcel, flags: int) { parcel.writestring(question) parcel.writestring(helptext) parcel.writedouble(qvalue) parcel.writestring(qtype.name) } ... }
and in test:
public class test(): parcelable { ... public var questions: arraylist<qbase> = arraylist() constructor(parcel: parcel?): this() { parcel?.let { ... parcel.readtypedlist(questions, qbase.creator) } } override fun writetoparcel(p: parcel?, p1: int) { p?.let { ... it.writetypedlist(questions) } } ... }
it exception:
caused by: java.lang.illegalstateexception: parcel.readstring() must not null @ com.vadim.hasdfa.justlearn.model.questions.utils.qbase.(qbase.kt:22) @ com.vadim.hasdfa.justlearn.model.questions.utils.qbase$creator.createfromparcel(qbase.kt:70) @ com.vadim.hasdfa.justlearn.model.questions.utils.qbase$creator.createfromparcel(qbase.kt:68) @ android.os.parcel.readtypedlist(parcel.java:2432) @ com.vadim.hasdfa.justlearn.model.test.(test.kt:28) @ com.vadim.hasdfa.justlearn.model.test$creator.createfromparcel(test.kt:47) @ com.vadim.hasdfa.justlearn.model.test$creator.createfromparcel(test.kt:45) @ android.os.parcel.readparcelable(parcel.java:2787) @ android.os.parcel.readvalue(parcel.java:2681) @ android.os.parcel.readarraymapinternal(parcel.java:3048) @ android.os.basebundle.unparcel(basebundle.java:257) @ android.os.basebundle.containskey(basebundle.java:435) @ android.content.intent.hasextra(intent.java:6859) @ com.vadim.hasdfa.justlearn.controller.activity.browsetest.showtestactivity.oncreate(showtestactivity.kt:28) @ android.app.activity.performcreate(activity.java:6980) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1213) @ android.app.activitythread.performlaunchactivity(activitythread.java:2770) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2892) @ android.app.activitythread.-wrap11(unknown source:0) @ android.app.activitythread$h.handlemessage(activitythread.java:1593) @ android.os.handler.dispatchmessage(handler.java:105) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6540) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)
Comments
Post a Comment