1

Teamアプリで型のオブジェクトを別の型に渡そうとしていますActivity

Teamクラス:

public class Team implements Parcelable {

    String teamName;

    //Name and Link to competition of Team
    TreeMap<String, String> competitions;
    //Name of competition with a map of matchdays with all games to a matchday
    TreeMap<String, HashMap<Integer, ArrayList<Event>>> matchDays;

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(teamName);
        dest.writeMap(competitions);    
    }

    public static final Parcelable.Creator<Team> CREATOR = new Parcelable.Creator<Team>() {
        public Team createFromParcel(Parcel in) {
            return new Team(in);
        }

        public Team[] newArray(int size) {
            return new Team[size];
        }
    };

    private Team(Parcel in) {
        teamName = in.readString();

        in.readMap(competitions, Team.class.getClassLoader());
    }
}

マーシャリング時に RuntimeException が発生します。

TreeMap<String, HashMap<Integer, ArrayList<Event>>> matchDays;

ネストされた TreeMap をクラスの残りの部分と一緒に渡すにはどうすればよいですか?

4

1 に答える 1

1

StringTreeMap、およびHashMapすべてがインターフェイスを実装しSerializableます。代わりに、クラスに実装SerializableしてTeamアクティビティ間で渡すことを検討してください。そうすることで、オブジェクトを から直接、BundleまたはIntent手動で解析することなくロードできるようになります。

public class Team implements Serializable {

    String teamName;

    //Name and Link to competition of Team
    TreeMap<String, String> competitions;
    //Name of competition with a map of matchdays with all games to a matchday
    TreeMap<String, HashMap<Integer, ArrayList<Event>>> matchDays;

追加の解析コードは必要ありません。

(編集:ArrayListも実装するため、このソリューションはクラスがシリアライズSerializable可能かどうかに依存します。)Event

于 2012-07-06T20:23:18.483 に答える