0
votes

I have an Object that I am passing between activities. In this Object there are seven variables. One of those variables is an ArrayList that is from another class.

I have implemented Parcelable on both.

Here are the errors:

09-08 17:00:04.212 18965-18965/it.sinesy.padova33 E/AndroidRuntime: FATAL EXCEPTION: main Process: it.sinesy.padova33, PID: 18965 java.lang.RuntimeException: Unable to start activity ComponentInfo{it.sinesy.padova33/org.thoughtcrime.securesms.ConversationListActivity}: java.lang.RuntimeException: Parcel android.os.Parcel@6e57f24: Unmarshalling unknown type code 7274612 at offset 548 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@6e57f24: Unmarshalling unknown type code 7274612 at offset 548 at android.os.Parcel.readValue(Parcel.java:2443) at android.os.Parcel.readListInternal(Parcel.java:2778) at android.os.Parcel.readArrayList(Parcel.java:2035) at org.thoughtcrime.securesms.util.ChatIntentParamenters.(ChatIntentParamenters.java:50) at org.thoughtcrime.securesms.util.ChatIntentParamenters$1.createFromParcel(ChatIntentParamenters.java:80) at org.thoughtcrime.securesms.util.ChatIntentParamenters$1.createFromParcel(ChatIntentParamenters.java:77) at android.os.Parcel.readParcelable(Parcel.java:2470) at android.os.Parcel.readValue(Parcel.java:2364) at android.os.Parcel.readArrayMapInternal(Parcel.java:2717) at android.os.BaseBundle.unparcel(BaseBundle.java:269) at android.os.Bundle.getParcelable(Bundle.java:840) at android.content.Intent.getParcelableExtra(Intent.java:6239) at org.thoughtcrime.securesms.ConversationListActivity.onCreate(ConversationListActivity.java:94) at org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity.onCreate(PassphraseRequiredActionBarActivity.java:48) at android.app.Activity.performCreate(Activity.java:6664) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)  at android.app.ActivityThread.-wrap12(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6077)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 

Here's my ChatIntentParamenters class parcelable code:

package org.thoughtcrime.securesms.util;
import android.os.Parcel;
import android.os.Parcelable;
import org.thoughtcrime.securesms.contacts.PlatformContact;
import java.util.ArrayList;
public class ChatIntentParamenters implements Parcelable {
    public static final String FLAG_YES = "Y";
    public static final String FLAG_NO = "N";
    private String title;
    private String additionalTitle;
    private boolean canCreateGroups;
    private boolean canCreateMessages;
    private boolean canDeleteMessages;
    private boolean canInviteFriends;

    private ArrayList<PlatformContact> preloadedContacts;

    public ChatIntentParamenters(String title, String additionalTitle, boolean canCreateGroups, boolean canCreateMessages, boolean canDeleteMessages, boolean canInviteFriends, ArrayList<PlatformContact> preloadedContacts) {

        this.title = title;
        this.additionalTitle = additionalTitle;
        this.canCreateGroups = canCreateGroups;
        this.canCreateMessages = canCreateMessages;
        this.canDeleteMessages = canDeleteMessages;
        this.canInviteFriends = canInviteFriends;

        this.preloadedContacts = preloadedContacts;


    }

    public ChatIntentParamenters(Parcel parcel) {
        this.title = parcel.readString();
        this.additionalTitle = parcel.readString();

        this.canCreateGroups = parcel.readString().equals(FLAG_YES);
        this.canCreateMessages = parcel.readString().equals(FLAG_YES);
        this.canDeleteMessages = parcel.readString().equals(FLAG_YES);
        this.canInviteFriends = parcel.readString().equals(FLAG_YES);

        this.preloadedContacts = parcel.readArrayList(PlatformContact.class.getClassLoader());

    }



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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(additionalTitle);

        dest.writeString(canCreateGroups?FLAG_YES:FLAG_NO);
        dest.writeString(canCreateMessages?FLAG_YES:FLAG_NO);
        dest.writeString(canDeleteMessages?FLAG_YES:FLAG_NO);
        dest.writeString(canInviteFriends?FLAG_YES:FLAG_NO);

        dest.writeList(preloadedContacts);

    }



    public final static Parcelable.Creator<ChatIntentParamenters> CREATOR = new Parcelable.Creator<ChatIntentParamenters>() {
        @Override
        public ChatIntentParamenters createFromParcel(Parcel source) {
            return new ChatIntentParamenters(source);
        }

        @Override
        public ChatIntentParamenters[] newArray(int size) {
            return new ChatIntentParamenters[size];
        }
    };


    public String getAdditionalTitle() {
        return additionalTitle;
    }

    public void setAdditionalTitle(String additionalTitle) {
        this.additionalTitle = additionalTitle;
    }

    public boolean isCanCreateGroups() {
        return canCreateGroups;
    }

    public void setCanCreateGroups(boolean canCreateGroups) {
        this.canCreateGroups = canCreateGroups;
    }

    public boolean isCanCreateMessages() {
        return canCreateMessages;
    }

    public void setCanCreateMessages(boolean canCreateMessages) {
        this.canCreateMessages = canCreateMessages;
    }

    public boolean isCanDeleteMessages() {
        return canDeleteMessages;
    }

    public void setCanDeleteMessages(boolean canDeleteMessages) {
        this.canDeleteMessages = canDeleteMessages;
    }

    public boolean isCanInviteFriends() {
        return canInviteFriends;
    }

    public void setCanInviteFriends(boolean canInviteFriends) {
        this.canInviteFriends = canInviteFriends;
    }

    public String getTitle() {
        return title;
    }

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

    public ArrayList<PlatformContact> getPreloadedContacts() {
        return preloadedContacts;
    }

    public void setPreloadedContacts(ArrayList<PlatformContact> preloadedContacts) {
        this.preloadedContacts = preloadedContacts;
    }
}

and PlatformContact, my second class that is inserted as an ArrayList object into ChatIntentParamenters:

package org.thoughtcrime.securesms.contacts;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * Classe per passare la lista dei contatti a signal, in modo che non li prenda dai contatti del telefono
 * Created by filippoboatto on 06/09/16.
 */

public class PlatformContact implements Parcelable {
    private long contactId;
    private String firstName;
    private String lastName;
    private String phoneNumber;
    private String imageURI;

    public PlatformContact (long contactId, String firstName, String lastName, String phoneNumber, String imageURI){
        this.contactId = contactId;
        this.firstName = firstName;
        this.lastName = lastName;
        this.phoneNumber = phoneNumber;
        this.imageURI = imageURI;
    }

    public PlatformContact(Parcel parcel) {
        this.contactId = parcel.readInt();
        this.firstName = parcel.readString();
        this.lastName = parcel.readString();
        this.phoneNumber = parcel.readString();
        this.imageURI = parcel.readString();
    }



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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(contactId);
        dest.writeString(firstName);
        dest.writeString(lastName);
        dest.writeString(phoneNumber);
        dest.writeString(imageURI);
    }



    public final static Creator<PlatformContact> CREATOR = new Creator<PlatformContact>() {
        @Override
        public PlatformContact createFromParcel(Parcel source) {
            return new PlatformContact(source);
        }

        @Override
        public PlatformContact[] newArray(int size) {
            return new PlatformContact[size];
        }
    };
}

then use the following code to put an ChatIntentParamenters into the intent:

ChatIntentParamenters params = new ChatIntentParamenters(title, additionalTitle, canCreateGroups, canCreateMessages, canDeleteMessages, false, contactsList);
intent.putExtra(ConversationListActivity.INTENT_PARAMS, params);
getActivity().startActivity(intent);

I have the error when I get intent extra in the activity:

ChatIntentParamenters params = intent.getParcelableExtra(INTENT_PARAMS);
1

1 Answers

1
votes

Try replacing

this.preloadedContacts = parcel.readArrayList(PlatformContact.class.getClassLoader())

with

    this.preloadedContacts= new ArrayList<>();
    parcel.readTypedList(this.preloadedContacts, PlatformContact.CREATOR);

and

    dest.writeList(preloadedContacts);

with

    dest.writeTypedList(preloadedContacts)