BadParcelableException

在接入融云的api时,写自定义消息,遇到了这个问题

在融云中自定义消息,要实现其Paceleable接口。

错误表现,在会话界面可以发送正常的自定义消息。
离开重返会话界面直接崩了,

定位到的错误信息看起来也很明显,没有能解析出本地的序列化化的数据,在Message的反序列方法中崩了。
错误定位:

   /**
     * Read and return a new Parcelable from the parcel.  The given class loader
     * will be used to load any enclosed Parcelables.  If it is null, the default
     * class loader will be used.
     * @param loader A ClassLoader from which to instantiate the Parcelable
     * object, or null for the default class loader.
     * @return Returns the newly created Parcelable, or null if a null
     * object has been written.
     * @throws BadParcelableException Throws BadParcelableException if there
     * was an error trying to instantiate the Parcelable.
     */
    @SuppressWarnings("unchecked")
    public final <T extends Parcelable> T readParcelable(ClassLoader loader) {

简单翻译:若参数不为空,将以此类加载器加载解析Parcel数据,若空,使用默认的类加载器。
返回反序列后的对象,若是NULL的对象被序列化,则反序列化也会返回空。
重点:若是空对象被写入,则解析返回的就是null.

可怕的是我跳过了注释中的那句话,
去看了这个:

*
 * Exception thrown when a {@link Parcelable} is malformed or otherwise invalid.
 * <p>
 * This is typically encountered when a custom {@link Parcelable} object is
 * passed to another process that doesn't have the same {@link Parcelable} class
 * in its {@link ClassLoader}.
 *  当自定义的Pacelable对象传给其他进程时,会出现当前进程加载不到当前类的情形,这是常见情形。
 */
public class BadParcelableException extends AndroidRuntimeException 

好吧,有点懵。
一句话总结,序列化对象时,注意检查写入的对象注意判空处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值