SAVVY SAVVY - 1 year ago 80
Android Question

How to parcelable object

I am trying to learn parcelable .Earlier I was using get and set function but now I am using parcelable to pass the object to other class I made the passdata class and implemented the parcelable but how I can add the list to the class object.

class Passdata implements Parcelable {
private String title,album;
private long duration;
private Uri data,album_art;

public String getTitle() {
return title;

void setTitle(String title) {
this.title = title;

public String getAlbum() {
return album;

void setAlbum(String album) {
this.album = album;

public long getDuration() {
return duration;

void setDuration(long duration) {
this.duration = duration;

public Uri getData() {
return data;

void setData(Uri data) { = data;

public Uri getAlbum_art() {
return album_art;

void setAlbum_art(Uri album_art) {
this.album_art = album_art;

Passdata(Parcel in) {
title = in.readString();
album = in.readString();
duration = in.readLong();
data = in.readParcelable(Uri.class.getClassLoader());
album_art = in.readParcelable(Uri.class.getClassLoader());

public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(data, flags);
dest.writeParcelable(album_art, flags);

public int describeContents() {
return 0;

public static final Creator<Passdata> CREATOR = new Creator<Passdata>() {
public Passdata createFromParcel(Parcel in) {
return new Passdata(in);

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

how can I add the object like this

do {
int audioTitle = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
int audioartist = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
int audioduration = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
int audiodata = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
int audioalbum = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
int audioalbumid = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
Passdata info = new Passdata();
// info.setArtist(audioCursor.getString(audioartist));
info.setAlbum_art(ContentUris.withAppendedId(albumArtUri, audioCursor.getLong(audioalbumid)));

I am getting error in the place were I am creating the passdata object
how to fix this??

Answer Source

You don't have empty constructor in PassData class. Add this code:

public Passdata() {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download