Question

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().

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);
    }
}

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.

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.

EDIT:

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.

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.

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.

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...

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.

best regards htz

Was it helpful?

Solution

Problem unmarshalling parcelables

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

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top