PhilJay/MPAndroidChart · error · ParcelFormatException
Cannot parcel an Entry with non-parcelable data
Error message
Cannot parcel an Entry with non-parcelable data
What it means
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.
Source
Thrown at MPChartLib/src/main/java/com/github/mikephil/charting/data/Entry.java:149
public String toString() {
return "Entry, x: " + x + " y: " + getY();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.x);
dest.writeFloat(this.getY());
if (getData() != null) {
if (getData() instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.getData(), flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
protected Entry(Parcel in) {
this.x = in.readFloat();
this.setY(in.readFloat());
if (in.readInt() == 1) {
this.setData(in.readParcelable(Object.class.getClassLoader()));
}
}
public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator<Entry>() {
public Entry createFromParcel(Parcel source) {
return new Entry(source);
}View on GitHub (pinned to 9c7275a059)
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.
Example fix
// before
entry.setData(myBusinessObject); // not Parcelable -> throws on saveInstanceState
// after
public class ChartMeta implements Parcelable {
public final long id;
protected ChartMeta(Parcel in){ this.id = in.readLong(); }
public void writeToParcel(Parcel dest, int flags){ dest.writeLong(id); }
public static final Creator<ChartMeta> CREATOR = ...;
}
entry.setData(new ChartMeta(42L)); Defensive patterns
Strategy: type-guard
Validate before calling
if (entry.getData() == null || entry.getData() instanceof android.os.Parcelable) {
// safe to parcel this Entry
} else {
entry.setData(null); // strip non-parcelable payload before state save
} Type guard
boolean isEntryDataParcelable(Entry e) {
return e.getData() == null || e.getData() instanceof android.os.Parcelable;
} Try / catch
try {
out.writeParcelable(entry, 0);
} catch (android.os.ParcelFormatException e) {
entry.setData(null);
Log.w(TAG, "Stripped non-parcelable Entry data", e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
AI-assisted analysis of PhilJay/MPAndroidChart@9c7275a059 (2026-08-14).
Data as JSON: /api/errors/c43db780cceaf5f4.
Report an issue: GitHub.