{"record":{"id":"c43db780cceaf5f4","repo":"PhilJay/MPAndroidChart","slug":"cannot-parcel-an-entry-with-non-parcelable-data","errorCode":null,"errorMessage":"Cannot parcel an Entry with non-parcelable data","messagePattern":"Cannot parcel an Entry with non-parcelable data","errorType":"exception","errorClass":"ParcelFormatException","httpStatus":null,"severity":"error","filePath":"MPChartLib/src/main/java/com/github/mikephil/charting/data/Entry.java","lineNumber":149,"sourceCode":"    public String toString() {\n        return \"Entry, x: \" + x + \" y: \" + getY();\n    }\n\n    @Override\n    public int describeContents() {\n        return 0;\n    }\n\n    @Override\n    public void writeToParcel(Parcel dest, int flags) {\n        dest.writeFloat(this.x);\n        dest.writeFloat(this.getY());\n        if (getData() != null) {\n            if (getData() instanceof Parcelable) {\n                dest.writeInt(1);\n                dest.writeParcelable((Parcelable) this.getData(), flags);\n            } else {\n                throw new ParcelFormatException(\"Cannot parcel an Entry with non-parcelable data\");\n            }\n        } else {\n            dest.writeInt(0);\n        }\n    }\n\n    protected Entry(Parcel in) {\n        this.x = in.readFloat();\n        this.setY(in.readFloat());\n        if (in.readInt() == 1) {\n            this.setData(in.readParcelable(Object.class.getClassLoader()));\n        }\n    }\n\n    public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator<Entry>() {\n        public Entry createFromParcel(Parcel source) {\n            return new Entry(source);\n        }","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/PhilJay/MPAndroidChart/blob/9c7275a0596a7ac0e50ca566e680f7f9d73607af/MPChartLib/src/main/java/com/github/mikephil/charting/data/Entry.java#L131-L167","documentation":"Thrown during Entry.writeToParcel() when an Entry has non-null data that does not implement android.os.Parcelable. Parceling an Entry serializes x, y, and an optional data payload; only Parcelable data can be written through writeParcelable, so any other object type causes a ParcelFormatException. The data field is set via Entry.setData(Object) and is opaque to the chart.","triggerScenarios":"Calling entry.setData(myPojo) where myPojo does not implement Parcelable, then saving the chart state to a Bundle/Parcel (e.g. onSaveInstanceState, passing across activities via intent). Putting an Entry list into a Bundle on a config change.","commonSituations":"Attaching arbitrary business objects to entries for tap-handling then relying on Android state restoration; serializing chart data across process boundaries; storing entries in savedInstanceState without making the payload Parcelable.","solutions":["Make the data object implement android.os.Parcelable (override writeToParcel and provide a CREATOR).","If you only need an id, store a primitive/String (wrap a small Parcelable) instead of a POJO.","Call entry.setData(null) before parceling if the payload is non-essential.","Use a separate lookup map keyed by x/y instead of stuffing non-parcelable data onto the Entry."],"exampleFix":"// before\nentry.setData(myBusinessObject); // not Parcelable -> throws on saveInstanceState\n\n// after\npublic class ChartMeta implements Parcelable {\n    public final long id;\n    protected ChartMeta(Parcel in){ this.id = in.readLong(); }\n    public void writeToParcel(Parcel dest, int flags){ dest.writeLong(id); }\n    public static final Creator<ChartMeta> CREATOR = ...;\n}\nentry.setData(new ChartMeta(42L));","handlingStrategy":"type-guard","validationCode":"if (entry.getData() == null || entry.getData() instanceof android.os.Parcelable) {\n    // safe to parcel this Entry\n} else {\n    entry.setData(null); // strip non-parcelable payload before state save\n}","typeGuard":"boolean isEntryDataParcelable(Entry e) {\n    return e.getData() == null || e.getData() instanceof android.os.Parcelable;\n}","tryCatchPattern":"try {\n    out.writeParcelable(entry, 0);\n} catch (android.os.ParcelFormatException e) {\n    entry.setData(null);\n    Log.w(TAG, \"Stripped non-parcelable Entry data\", e);\n}","preventionTips":["Make any object attached via setData() implement Parcelable.","Avoid attaching POJOs to entries; keep a separate lookup keyed by x/y.","Test onSaveInstanceState/restore on screens that carry chart data."],"tags":["parcelable","entry","serialization","android-state"],"backgroundTag":null,"analyzedSha":"9c7275a0596a7ac0e50ca566e680f7f9d73607af","analyzedAt":"2026-08-14T00:17:56.136Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}