In my app I have a class CurrentGame
, which I set up according to the example in this question: Android Class Parcelable with ArrayList
However, I don't know how to add the intArray scoresRnd
to the Parcel Constructor.
When I add this line, for example, it gets underlined in red:
this.scoresRnd = parcel.readArray(null);
...and I get this error message "Incompatible types. Required: Int[]. Found: java.lang.Object[]". Can you please help me? Thanks! (Also, please point out any other mistakes in my code)
public class CurrentGame implements Parcelable{
private int rnd;
private int[] scoresRnd;
private ArrayList<int[]> scoreList;
public CurrentGame(){
super();
this.rnd = 0;
this.scoresRnd = new int[]{0,0,0,0};
this.scoreList = new ArrayList<>();
}
public CurrentGame (Parcel parcel){
this.scoreList = parcel.readArrayList(null);
this.rnd = parcel.readInt();
//WHAT DO I PUT HERE FOR THE INTARRAY???
}
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
// TODO Auto-generated method stub
parcel.writeList(this.scoreList);
parcel.writeInt(this.rnd);
}
public static final Creator<CurrentGame> CREATOR = new Creator<CurrentGame>() {
@Override
public CurrentGame createFromParcel(Parcel parcel) {
// TODO Auto-generated method stub
return new CurrentGame(parcel);
}
@Override
public CurrentGame[] newArray(int i) {
// TODO Auto-generated method stub
return new CurrentGame[i];
}
};
public void expandList(int[] scoresRnd){
scoreList.add(scoresRnd);
}
public void setRound(int rnd){
this.rnd=rnd;
}
public int getRound(){
return rnd;
}
public ArrayList<int[]> getScoreList(){
return scoreList;
}
}