AndroidRuntime错误:包裹无法编组值

时间:2016-02-16 05:29:36

标签: java android parcelable

我编写了一个这样的类。但是当我使用它时,在这个覆盖的方法中出现了运行时错误

 @Override
 public void writeToParcel(Parcel dest, int flags) {
     dest.writeValue(synclistener);
 }

MYCLASS

public class SyncListenEntity implements Parcelable {
    private LocationServiceProvider.LocationSyncNotifier synclistener;

    public LocationServiceProvider.LocationSyncNotifier getSynclistener() {
        return synclistener;
    }

    public void setSynclistener(LocationServiceProvider.LocationSyncNotifier synclistener) {
        this.synclistener = synclistener;
    }

    public SyncListenEntity() {
    }

    protected SyncListenEntity(Parcel in) {
        synclistener = (LocationServiceProvider.LocationSyncNotifier) in.readValue(LocationServiceProvider.LocationSyncNotifier.class.getClassLoader());
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(synclistener);
    }


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

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

LocationNotifier

public interface LocationNotifier {
     void onNewLocationArrived(Location loaction, String privider);
}

例外:

java.lang.RuntimeException: Parcel: unable to marshal value
Caused by: java.lang.RuntimeException: Parcel: unable to marshal value
     com.library.gps.SyncListenEntity.writeToParcel(SyncListenEntity.java)
     android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:3835‌​)
     com.library.gps.LocationServiceProvider.enableUserTrackingService(LocationServic‌​eProvider.java:64)
     com.ceylonlinux.multilac.activity.FrmHome.onCreate(FrmHome.java:365) 

1 个答案:

答案 0 :(得分:3)

您正在尝试使用writeParcel()来编写不符合文档中所述要求的对象。您只能将值写入javadoc中所述类型的包中。