1

2 つのフラグメント間でデータを渡したいです。渡すデータは、SongDetails クラスのオブジェクトです。データを渡すフラグメントのコードは次のとおりです。

ArrayList<SongDetails> Songinfo =new........;
if (Songinfo.size()>0)//Songinfo is an object of the class SongDetails..

        {
         Bundle bundle = new Bundle();

         bundle.putParcelableArrayList("Fragdata",Songinfo);
         dv.setArguments(bundle);

        }

データを受信するためのコード

Bundle bundle=this.getArguments(); 
    final ArrayList<SongDetails> Songinfo =bundle.getParcelableArrayList("Fragdata"); 

これを実行すると、アプリがクラッシュします...何が間違っていますか??

SongDetails のコード

package sourcecode.jazzplayer;


import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public class SongDetails implements Parcelable {
    Bitmap icon;
    String song;
    String Artist;
    String Album;
    String Path;
    int time;
    int icLauncher;

    public SongDetails() {
    }

    public SongDetails(Parcel in) {
        String[] data = new String[4];
        in.readStringArray(data);
        this.Path = data[0];
        this.song= data[1];
        this.Album= data[2];
        this.Artist = data[3];
    }

    public String getSong() {
        return song;
    }

    public void setSong(String song) {
        this.song = song;
    }

    public String getArtist() {
        return Artist;
    }

    public void setArtist(String Artist) {
        this.Artist = Artist;
    }

    public Bitmap getIcon() {
        return icon;
    }

    public void setIcon(Bitmap bitmap) {
        this.icon = bitmap;
    }

    public String getPath2() {
        return Path;
    }

    public void setPath2(String Path) {
        this.Path = Path;
    }

    public String getAlbum() {
        return Album;
    }

    public void setAlbum(String Album) {
        this.Album = Album;
    }

    public void setIcon(int icLauncher) {
        this.icLauncher = icLauncher;
    }










    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeStringArray(new String[] { this.Path,this.song,this.Album,this.Artist });

    }

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

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

2 に答える 2