私はCollection []配列をintentExtraに渡したいが、それは動作しません。他のアクティビティで なぜオブジェクト配列をオブジェクトの配列に渡すことができないのですか?
Intent intent = new Intent(SzabadEuMusorokLeirasActivity.this, SzabadEuMusorokViewActivity.class);
JSONdata jsonData = new JSONdata("http://1956.osaarchivum.org/api/items?collection=13");
intent.putExtra("ARRAY_EXTRA", jsonData.getCollections());
startActivity(intent);
:
Intent intent = getIntent();
Parcelable[] parcelables = intent.getParcelableArrayExtra("ASD");
mCollections = Arrays.copyOf(parcelables, parcelables.length, Collection[].class);
それはparcelables.lengthがnullであるので、それはNullPointerExceptionが取得mCollections = Arrays.copyOf(...)ラインに入った場合...
ここはコレクションクラスである:
public class Collection implements Parcelable{
private String mTitile;
private String mSubject;
private String mMediaURL;
public Collection() {}
protected Collection(Parcel in){
mTitile = in.readString();
mSubject = in.readString();
mMediaURL = in.readString();
}
public static final Creator<Collection> CREATOR = new Creator<Collection>() {
@Override
public Collection createFromParcel(Parcel in) {
return new Collection(in);
}
@Override
public Collection[] newArray(int size) {
return new Collection[size];
}
};
public String getTitile() {
return mTitile;
}
public void setTitile(String titile) {
mTitile = titile;
}
public String getSubject() {
return mSubject;
}
public void setSubject(String subject) {
mSubject = subject;
}
public String getMediaURL() {
return mMediaURL;
}
public void setMediaURL(String mediaURL) {
mMediaURL = mediaURL;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mTitile);
dest.writeString(mSubject);
dest.writeString(mMediaURL);
}
}
[this](http://stackoverflow.com/questions/5460222/pass-an-array-of-custom-objects-android)の質問と[this] (http://stackoverflow.com/questions/13778485/how-do-i-send-an-array-of-objects-from-one-activity-to-another) –
[オブジェクトを送信する方法1つのAndroidのアクティビティをインテントを使用して別のものに移動する?](http://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – theduck