BadParcelableException:ClassNotFoundException的解组时:(空的类名) [英] BadParcelableException: ClassNotFoundException when unmarshalling: (empty classname)

查看:357
本文介绍了BadParcelableException:ClassNotFoundException的解组时:(空的类名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为AllStatStruct类。此类包含三个属性,这是我的班StatStructCycle,StatStructHistory和MatrixStruct的对象。每类扩展类DataStruct并实现Parcelable接口。在接口的实现,每一个类被读取并通过书面 readParceable() writeParceable()

I have a class named AllStatStruct. This class contains three attributes, which are objects of my classes StatStructCycle, StatStructHistory and MatrixStruct. Every class extends the class DataStruct and implements the Parcelable interface. In the implementation of the interface, every class is read and written by using readParceable() or writeParceable().

在我的活动,我呼吁在AsyncTask的一个SOAP Web服务,并获得类 AllStatStruct 的对象。这个目的是通过创建传递到下一个活动捆绑

In my Activity, I call a SOAP webservice in an AsyncTask and get an object of the class AllStatStruct. This object is passed to the next Activity by creating a Bundle:

protected void onPostExecute(final AllStatStruct ass) {

    if (ass != null) {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }

        Bundle bundle = new Bundle();
        bundle.putParcelable("allStatStruct", ass);
        intent = new Intent(packageContext, PrivateView.class);
        intent.putExtras(bundle);
        startActivity(intent);

    } else {
        KreativBarometerMainView.this.showDialog(9999);
    }
}

编组包裹效果很好,因为我可以在我的LogCat中跟踪输出看到。但解编包裹的时候,一个ClassNotFoundException发生,我不知道为什么。这是跟踪:

Marshalling the parcel works well, as I can see at my trace outputs in the LogCat. But when unmarshalling the parcel, a ClassNotFoundException occurs and I have no idea why. This is the trace:

05-11 15:02:59.796: E/AndroidRuntime(8647): Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: 
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Parcel.readParcelable(Parcel.java:1958)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at de.kreativBarometer.net.structs.AllStatStruct.<init>(AllStatStruct.java:45)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at de.kreativBarometer.net.structs.AllStatStruct$1.createFromParcel(AllStatStruct.java:70)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at de.kreativBarometer.net.structs.AllStatStruct$1.createFromParcel(AllStatStruct.java:1)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Parcel.readParcelable(Parcel.java:1981)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Parcel.readValue(Parcel.java:1846)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Parcel.readMapInternal(Parcel.java:2083)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Bundle.unparcel(Bundle.java:208)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.os.Bundle.getParcelable(Bundle.java:1100)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at de.kreativBarometer.ui.PrivateView.onCreate(PrivateView.java:693)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-11 15:02:59.796: E/AndroidRuntime(8647):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1628)
05-11 15:02:59.796: E/AndroidRuntime(8647):     ... 11 more

正如你所看到的,有没有为找不到类给出的名字!所以它是寻找一个名为当然它是没有找到类。

As you can see, there is no name given for the not found class! So it is searching for a class named "" and of course it is not found.

我不知道,为什么出现这种情况。有人能帮助我吗?我已经试过玩的类加载器,但给人的意图额外的类加载器,并使用这一个来解读Parcelables并不起作用。

I have no idea, why this occurs. Can someone help me? I already tried to play around with the ClassLoader, but giving the intent an extra classloader and using this one to unmarshall the parcelables does not work.

编辑:

如你所说,我试图通过单独的AllStatStruct的几个部分。它工作正常使用 StatStructCycle MatrixStruct ,但与 StatStructHistory ,还有抛出一个错误。

As you suggested, I tried to pass the several parts of the AllStatStruct seperately. It works fine with the StatStructCycle and the MatrixStruct, but with the StatStructHistory, there is still an error thrown.

现在,我收到了 NullPointerException异常,当我试图来解读我的 StatStructCycle 的ArrayList,它出现。我注释掉历史的其他部分。

Now, I get a NullPointerException, when I try to unmarshall my ArrayList with StatStructCycles in it. I commented out the other parts of the history.

我试着写和读与 writeTypedList ArrayList中(列表&LT; T&GT;清单) readTypedList(列表&LT; T&GT;列表中,造物主&LT; T&GT; C),但它不工作或者

I tried to write and read the ArrayList with writeTypedList(List<T> list) and readTypedList(List<T> list, Creator<T> c), but it is not working either.

由于我使用的ArrayList,我也通过修剪其能力,以自己的实际大小 trimToSize(),因为我认为ArrayList的空插槽可能会导致问题。但同样,这种情况并非如此...

As I am using ArrayLists, I also trimmed their capacity to their real size by using trimToSize(), because I thought the "empty" slots of the ArrayList could cause the problem. But again, this is not the case...

启动应用程序的调试器显示,该整理 StatStructHistory 有没有空值......每个属性或列表项被初始化。我不知道在哪里这个 NullPointerException异常的来源。

Starting the App with the debugger shows, that the marshalled StatStructHistory has no empty values... every attribute or listitem is initialized. I have no idea where this NullPointerException is coming from.

最好的问候
HTZ

best regards htz

推荐答案

问题解组Parcelables并

看起来即使你编组成功,解组过程中仍然可以,如果有异常空失败。

Looks like even if your marshalling is successful, the unmarshall process can still fail if there are null exceptions.

有关调试目的,尝试编组你的每一个子对象一个接一个。看看其中的任何错误了,那么研究这个问题。现在,你想一下子unmarhsall 3个对象,它是很难确定哪一个是有一个问题(如果有的话)。

For debugging purposes, try marshalling each one of your sub-objects one by one. See if any of them error out, then dig into the problem. Right now you're trying to unmarhsall 3 objects at once and it's hard to pin point which one is having an issue (if any).

如果还不清楚,我建议尝试此:

If it's not clear, I'm suggesting trying this:

bundle.putParcelable("allStatStruct", ass.StatStructCycle); 

如果这样的作品,尝试:

If that works, try:

bundle.putParcelable("allStatStruct", ass.StatStructHistory); 

等等......

etc...

这篇关于BadParcelableException:ClassNotFoundException的解组时:(空的类名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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