Cannot pass custom Object in an Intent: The Method Put Extra is Ambiguous for the type Intent

The first error: ‘The Method Put Extra is Ambiguous for the type Intent’.

The class Car is both Serializable and Parcelable, the compiler doesn’t know whether to use putExtra(Serializable s) or putExtra(Parcelable p) to handle your request. So you have to cast your Car to one of them when using Intent.putExtra().

Intent.putExtra("car", (Parcelable)myCarObject);
Intent.putExtra("car", (Serializable)myCarObject);

The second error: java.lang.ClassCastException: java.util.ArrayList

You put the Car object in a ArrayList and use putExtra to send to the next activity. An ArrayList is not Parcelable but only Serializable. The putExtra(ArrayList) works as putExtra(Serializable), but you read it by getParcelable(). An ArrayList cannot be cast to Parcelable.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)