I have a problem when I write pracelable object and receive from another application that I wrote. Everytime when I tried to get the object it always turned out to be BadParcelableException: ClassNotFoundException when unmarshalling.

I've been looking around and wonder if it turned out bad when I send to another application. Or it's simply I had error in my codes.

Please tell me where did I go wrong.

my sending lines:

ParcelableObject myObject = new ParcelableObject();
myObject = new ParcelableObject(result_name, resut_lv, result_race, 
    result_job, result_nation, result_guild, result_mission);
intent.putExtra("ACTION_DATA_TRANSFER", myObject);
intent.setClassName(target_app, target_app+".ReceiveMain");
startActivity(intent);

my receive lines:

ParcelableObject myObject = new ParcelableObject();
myObject = getIntent().getParcelableExtra("ACTION_DATA_TRANSFER"); //always crashed at this line

if (getIntent().hasExtra("ACTION_DATA_TRANSFER")) {
    Log.w("****CHECKING****", myObject.getName());
    item1.setText("The Character's name is: " + myObject.getName());
} else {
    Toast.makeText(getApplicationContext(), "There is not data passed yet", 
        Toast.LENGTH_LONG).show();
}

my ParcelableObject class:

private String name;
private int lv;
private String race;
private String job;
private String nation;
private String guild;
public String mission;

public void setName(String name) {
    this.name = name;
}

public void setLv(int lv) {
    this.lv = lv;
}

public void setRace(String race) {
    this.race = race;
}

public void setJob(String job) {
    this.job = job;
}

public void setNation(String nation) {
    this.nation = nation;
}

public void setGuild(String guild) {
    this.guild = guild;
}

public void setMission(String mission) {
    this.mission = mission;
}

public ParcelableObject(String name, int lv, String race, String job, String
     nation, String guild, String mission) {
    // TODO Auto-generated constructor stub
    this.name = name;
    this.lv = lv;
    this.race = race;
    this.job = job;
    this.nation = nation;
    this.guild = guild;
    this.mission = mission;
}

public String getName() {
    return name;
}

public int getLv() {
    return lv;
}

public String getRace() {
    return race;
}

public String getJob() {
    return job;
}

public String getNation() {
    return nation;
}

public String getGuild() {
    return guild;
}

public String getMission() {
    return mission;
}

@Override
public int describeContents() {
    // TODO Auto-generated method stub
    Log.w("****PO CHECKING****", "describeContents called");
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    // TODO Auto-generated method stub
    Log.w("****PO CHECKING****", "writeToParcel called");
    dest.writeString(name);
    dest.writeString(job);
    dest.writeInt(lv);
    dest.writeString(race);
    dest.writeString(guild);
    dest.writeString(nation);       
    dest.writeString(mission);
}

public ParcelableObject() {
    // TODO Auto-generated constructor stub
    super();
    Log.i("**check if exist**", "start parcel");
}

public static final Parcelable.Creator<ParcelableObject> CREATOR = 
    new Parcelable.Creator<ParcelableObject>() {

    @Override
    public ParcelableObject createFromParcel(Parcel in) {
        // TODO Auto-generated method stub
        Log.w("checking out", "createFromParcel");
        ParcelableObject pObject = new ParcelableObject();
        pObject.name = in.readString();
        pObject.job = in.readString();
        pObject.lv = in.readInt();
        pObject.race = in.readString();
        pObject.guild = in.readString();
        pObject.nation = in.readString();
        pObject.mission = in.readString();

        return pObject;
    }

    @Override
    public ParcelableObject[] newArray(int size) {
        // TODO Auto-generated method stub
        return new ParcelableObject[size];
    }
};

EDIT: To clarify before some people think I am a lazy noob, I have been looking for answer to solve the cause for this but without any luck. I looked up many people's code and tested out many times but still can't get my app right. So that is why I am here to ask help. If some people still think I am a lazy noob, I guess I am too lazy for some people to draw that conclusion. I should reconsider of my action again.

My situation is:

I wrote 2 apps and one is sending a parcelable object to another application. First app it's working correctly to send the object to another. However, as the second app receive it, it goes wrong and gives out the BadParcelableException as I run the process. I am not using bundle because I saw many examples that it is not necessary to do so. If I have been wrong please correct me.

2

There are 2 best solutions below

0
On

I found the answer that related to this topic... Is using Parcelable the right way to send data between applications?

Thank you all for the comments from above....

2
On

I've solved my case by using serializable instead of Parcelable.

but in your case here try parsing the object like this

myObject = (ParcelableObject)getIntent().getParcelableExtra("ACTION_DATA_TRANSFER");