难度的parcelable解组 [英] Difficulty with unmarshalling in parcelable

查看:235
本文介绍了难度的parcelable解组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是写一个包裹

我的code

 公共无效writeToParcel(DEST包裹,诠释标志){
        dest.writeString(poiDescription);
        dest.writeString(纬度);
        dest.writeString(经度);
        dest.writeString(地名);
        dest.writeString(plistPath);
        dest.writeString(poiDirName);
            如果(NULL!= isMascot present)
                dest.writeString(isMascot present);
            如果(NULL!= startMascottTime)
                dest.writeInt(startMascottTime);
            如果(NULL!= mascottDuration)
                dest.writeInt(mascottDuration);
}公共PointOfInterest(包裹源){
        poiDescription = source.readString();
        纬度= source.readString();
        经度= source.readString();
        地名= source.readString();
        plistPath = source.readString();
        poiDirName = source.readString();
        audioLinkDownload = source.readString();
        audioLinkStream = source.readString();
        poiName = source.readString();
        poiIndex = source.readInt();
        poiPaused = source.readString();
        source.readList(图像列表,NULL);
        source.readList(durationList,NULL);
        如果(NULL!= isMascot present)
            isMascot present = source.readString();
        如果(NULL!= startMascottTime)
               startMascottTime = source.readInt();
        如果(NULL!= mascottDuration)
                  mascottDuration = source.readInt();
}
这是我正在读的值
listOfPOI = getIntent()getParcelableArrayListExtra(POI);

这codw工作正常不高于吉祥物。

但是,当我添加有关吉祥物的3条线,我的应用程序崩溃。我打破我的头onthis,我没有得到为什么会这样,任何人都可以请让我知道这个问题?

我收到运行时异常和问题说有解组错误的parcelable

这是我收到的例外

  ERROR / AndroidRuntime(2061):致命异常:主要
 ERROR / AndroidRuntime(2061):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.Invenger / com.Invenger.Player.Audio}了java.lang.RuntimeException:地块android.os.Parcel@40570848:解组未知类型code 7536748偏移1064
 ERROR / AndroidRuntime(2061):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
 ERROR / AndroidRuntime(2061):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
 ERROR / AndroidRuntime(2061):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
 ERROR / AndroidRuntime(2061):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)
 ERROR / AndroidRuntime(2061):在android.os.Handler.dispatchMessage(Handler.java:99)
 ERROR / AndroidRuntime(2061):在android.os.Looper.loop(Looper.java:130)
 ERROR / AndroidRuntime(2061):在android.app.ActivityThread.main(ActivityThread.java:3683)
 ERROR / AndroidRuntime(2061):在java.lang.reflect.Method.invokeNative(本机方法)
 ERROR / AndroidRuntime(2061):在java.lang.reflect.Method.invoke(Method.java:507)
 ERROR / AndroidRuntime(2061):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
ERROR / AndroidRuntime(2061):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 ERROR / AndroidRuntime(2061):在dalvik.system.NativeStart.main(本机方法)
 ERROR / AndroidRuntime(2061):了java.lang.RuntimeException:地块android.os.Parcel@40570848:致解组未知类型code 7536748偏移1064
 ERROR / AndroidRuntime(2061):在android.os.Parcel.readValue(Parcel.java:1913)
 ERROR / AndroidRuntime(2061):在android.os.Parcel.readListInternal(Parcel.java:2092)
 ERROR / AndroidRuntime(2061):在android.os.Parcel.readArrayList(Parcel.java:1536)
 ERROR / AndroidRuntime(2061):在android.os.Parcel.readValue(Parcel.java:1867)
ERROR / AndroidRuntime(2061):在android.os.Parcel.readMapInternal(Parcel.java:2083)
ERROR / AndroidRuntime(2061):在android.os.Bundle.unparcel(Bundle.java:208)
ERROR / AndroidRuntime(2061):在android.os.Bundle.getParcelableArrayList(Bundle.java:1144)
 ERROR / AndroidRuntime(2061):在android.content.Intent.getParcelableArrayListExtra(Intent.java:3448)
    ERROR / AndroidRuntime(2061):在com.Invenger.Player.Audio.onCreate(Audio.java:162)
    ERROR / AndroidRuntime(2061):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
   ERROR / AndroidRuntime(2061):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
   ERROR / AndroidRuntime(2061):11 ...更多


解决方案

我莫名其妙地解决了这一问题。我把它作为静态的,而不是使之成为parcelable.Ihis可能不是标准的方式,使静态的。但是我觉得有关于地块的大小有限制。如果我增加一些15或更多变量它不工作。因此,它是为我工作了。

任何更好的答案将被接受

Here is my code of writing to a parcel

public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(poiDescription);
        dest.writeString(latitude);
        dest.writeString(longitude);
        dest.writeString(placeName);
        dest.writeString(plistPath);
        dest.writeString(poiDirName);
            if (null != isMascotPresent)
                dest.writeString(isMascotPresent);
            if (null != startMascottTime)
                dest.writeInt(startMascottTime);
            if (null != mascottDuration)
                dest.writeInt(mascottDuration);
}

public PointOfInterest(Parcel source) { 
        poiDescription = source.readString();
        latitude = source.readString();
        longitude = source.readString();
        placeName = source.readString();
        plistPath = source.readString();
        poiDirName = source.readString();
        audioLinkDownload = source.readString();
        audioLinkStream = source.readString();
        poiName = source.readString();
        poiIndex = source.readInt();
        poiPaused = source.readString();
        source.readList(imageList, null);
        source.readList(durationList, null);
        if (null != isMascotPresent)
            isMascotPresent = source.readString();
        if (null != startMascottTime)
               startMascottTime=source.readInt();
        if (null != mascottDuration)
                  mascottDuration=source.readInt();
}


This is how I am reading the values
listOfPOI = getIntent().getParcelableArrayListExtra("poi");

This codw works fine without the mascot above.

But when I add those 3 lines about mascot, my application is crashing. I am breaking my head onthis, I am not getting why is this happening, can anyone please let me know the issue?

I am getting the run time exception and problem saying there is unmarshalling error for the parcelable

This is the exception I am getting

 ERROR/AndroidRuntime(2061): FATAL EXCEPTION: main
 ERROR/AndroidRuntime(2061): java.lang.RuntimeException: Unable to start activity       ComponentInfo{com.Invenger/com.Invenger.Player.Audio}: java.lang.RuntimeException: Parcel android.os.Parcel@40570848: Unmarshalling unknown type code 7536748 at offset 1064
 ERROR/AndroidRuntime(2061):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
 ERROR/AndroidRuntime(2061):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
 ERROR/AndroidRuntime(2061):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
 ERROR/AndroidRuntime(2061):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
 ERROR/AndroidRuntime(2061):     at android.os.Handler.dispatchMessage(Handler.java:99)
 ERROR/AndroidRuntime(2061):     at android.os.Looper.loop(Looper.java:130)
 ERROR/AndroidRuntime(2061):     at android.app.ActivityThread.main(ActivityThread.java:3683)
 ERROR/AndroidRuntime(2061):     at java.lang.reflect.Method.invokeNative(Native Method)
 ERROR/AndroidRuntime(2061):     at java.lang.reflect.Method.invoke(Method.java:507)
 ERROR/AndroidRuntime(2061):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
ERROR/AndroidRuntime(2061):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
 ERROR/AndroidRuntime(2061):     at dalvik.system.NativeStart.main(Native Method)
 ERROR/AndroidRuntime(2061): Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@40570848: Unmarshalling unknown type code 7536748 at offset 1064
 ERROR/AndroidRuntime(2061):     at android.os.Parcel.readValue(Parcel.java:1913)
 ERROR/AndroidRuntime(2061):     at android.os.Parcel.readListInternal(Parcel.java:2092)
 ERROR/AndroidRuntime(2061):     at android.os.Parcel.readArrayList(Parcel.java:1536)
 ERROR/AndroidRuntime(2061):     at android.os.Parcel.readValue(Parcel.java:1867)
ERROR/AndroidRuntime(2061):     at android.os.Parcel.readMapInternal(Parcel.java:2083)
ERROR/AndroidRuntime(2061):     at android.os.Bundle.unparcel(Bundle.java:208)
ERROR/AndroidRuntime(2061):     at   android.os.Bundle.getParcelableArrayList(Bundle.java:1144)
 ERROR/AndroidRuntime(2061):     at android.content.Intent.getParcelableArrayListExtra(Intent.java:3448)
    ERROR/AndroidRuntime(2061):     at com.Invenger.Player.Audio.onCreate(Audio.java:162)
    ERROR/AndroidRuntime(2061):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
   ERROR/AndroidRuntime(2061):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
   ERROR/AndroidRuntime(2061):     ... 11 more

解决方案

I fixed the problem somehow. I made it as static instead of making it parcelable.Ihis may not be the standard way, of making it static. But I feel that there is a limit on the size of parcel. If I add some 15 or more variable it is not working. So it is working for me now.

Any better answer will be accepted

这篇关于难度的parcelable解组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆