Sto provando a scrivere un array di oggetti che implementano Parcelable in un Parcel utilizzando writeParcelableArray.Scrittura di matrici di Parcelables su un pacco in Android
Gli oggetti che sto cercando di scrivere sono definiti (come ci si aspetterebbe) come:
public class Arrival implements Parcelable {
/* All the right stuff in here... this class compiles and acts fine. */
}
e sto cercando di scriverle in un `Parcel' con:
@Override
public void writeToParcel(Parcel dest, int flags) {
Arrival[] a;
/* some stuff to populate "a" */
dest.writeParcelableArray(a, 0);
}
Quando Eclipse tenta di compilare questo ottengo l'errore:
Bound mismatch: The generic method writeParcelableArray(T[], int) of type Parcel is not applicable for the arguments (Arrival[], int). The inferred type Arrival is not a valid substitute for the bounded parameter < T extends Parcelable >
sono completamente non capisco questo messaggio di errore. Parcelable
è un'interfaccia (non una classe), quindi non è possibile estenderla. Qualcuno ha qualche idea?
UPDATE: Sto avendo sostanzialmente lo stesso problema quando porre ArrayList
di Parcelable
s in un Intent
:
Intent i = new Intent();
i.putParcelableArrayListExtra("locations", (ArrayList<Location>) locations);
rendimenti:
The method putParcelableArrayListExtra(String, ArrayList< ? extends Parcelable >) in the type Intent is not applicable for the arguments (String, ArrayList< Location >)
Ciò può essere perché era il Location
classe che stavo lavorando sopra (che avvolge il Arrival
s), ma io non la penso così.
Come ho detto, dichiara il tuo array usando l'interfaccia. Sono felice che tu l'abbia risolto. – harschware