Android. OS. BadParcelableException: ClassNotFoundException when unmarshalling

Source: Internet
Author: User

Add a List field to the person class in the data of the class object in the previous article Activity, as shown below:

Package com. linc. meta; import android. OS. parcel; import android. OS. parcelable; public class Person implements Parcelable {private String Name = null; private String Gender = null; private int HP = 0; private String Summary = null; private String Skill = null; private List <String> skillList = new ArrayList <String> (); public Person (String name, String gender, int HP, String summary, String skill) {this. name = name; this. gender = gender; this. summary = summary; this. HP = HP; this. skill = skill;} public String getName () {return Name;} public void setName (String name) {Name = name;} public String getGender () {return Gender ;} public void setGender (String gender) {Gender = gender;} public int getHP () {return HP;} public void setHP (int hP) {HP = hP ;} public String getSummary () {return Summary;} public void setSummary (String summary) {Summary = summary;} public String getSkill () {return Skill;} public void setSkill (String skill) {Skill = skill;} // Describe the kinds of special objects contained in this Parcelable's specified alled representation. // CONTENTS_FILE_DESCRIPTOR @ Override public int describeContents () {// TODO Auto-generated method stub return 0 ;} // This method writes the class data to the external provided Parcel @ Override public void writeToParcel (Parcel dest, int flags) {dest. writeString (Name); dest. writeString (Gender); dest. writeString (Summary); dest. writeInt (HP); dest. writeString (Skill);} public static final Parcelable. creator <Person> CREATOR = new Creator <Person> () {@ Override public Person createFromParcel (Parcel source) {return new Person (source );} @ Override public Person [] newArray (int size) {return new Person [size] ;}}; private Person (Parcel dest) {this. name = dest. readString (); this. gender = dest. readString (); this. summary = dest. readString (); this. HP = dest. readInt (); this. skill = dest. readString (); this. skillList = dest. readArrayList (String. class. getClassLoader (); // class loader must be specified }}

The class loader of the type should be introduced into the List. Otherwise, the above error will be reported.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.