Parcelable protocol requires a parcelable. creator object called .....

Source: Internet
Author: User
Public class person implements parcelable {// member variable private int ID; private string name; // 1. parcelable must be implemented. creator interface. Otherwise, an error is returned when you obtain the person data, as shown in the following code: // android. OS. badparcelableexception: // parcelable protocol requires a parcelable. creator object called Creator on class COM. um. demo. person // 2. this interface reads the person data from the Percel container and returns the person object to the logic layer. // 3. implement parcelable. the Object Name of the Creator interface must be creator. It is better to report the error mentioned above. // 4. when reading data in the parcel container, the data must be read in the Order stated by the member variables. Otherwise, an error occurred while obtaining the data. // 5. deserialization object public static final parcelable. creator <person> creator = new creator () {@ override public person createfromparcel (parcel source) {// todo auto-generated method stub // The data must be read in the order declared by the member variables. Otherwise, an error occurred while obtaining the data. Person P = new person (); p. setid (source. readint (); p. setname (source. readstring (); Return P ;}@ override public person [] newarray (INT size) {// todo auto-generated method stub return new person [size] ;}}; public int GETID () {return ID;} public void setid (int id) {This. id = ID;} Public String getname () {return name;} public void setname (string name) {This. name = Name ;}@ override public int describecontents () {// todo auto-generated method stub return 0 ;}@ override public void writetoparcel (parcel DEST, int flags) {// todo auto-generated method stub // 1. data must be encapsulated in the order declared by the member variables. Otherwise, an error occurred while obtaining data. // 2. serialized object DeST. writeint (ID); DeST. writestring (name );}}

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.