Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8875967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:06:25+00:00 2026-06-14T19:06:25+00:00

In my project I have a model which holds basic information about model. For

  • 0

In my project I have a model which holds basic information about model. For example lets say that the model is a Car. Then there are many different varieties of Cars and these have different data assigned to them. All models must be parcelables.

The differences between different cars is very small, it might just be a few data fields. So this is solved by creating presenters (just a class that holds data) for the different cars. The presenter would then know which extra data it should hold. Because the the presenter itself is not parcelable it will have a Bundle for all its data which then the Car class will then add to the parcelable. I don’t want to make the presenters into parcelables.

So Car takes the Bundle from the presenter and puts it in its parcel:

  public void writeToParcel(Parcel parcel, int flags) {
    parcel.writeBundle(getPresenter().getBundle());
  } 

And it will then unpack it with:

  public Car(Parcel parcel) {    
    getPresenter().setBundle(parcel.readBundle());
  }

This works fine until a parcelable object is added to the bundle by the presenter.
Then I get this error:

11-16 15:06:37.255: E/AndroidRuntime(15193): FATAL EXCEPTION: main
11-16 15:06:37.255: E/AndroidRuntime(15193): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.activity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.model.engine
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.app.ActivityThread.access$600(ActivityThread.java:142)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Looper.loop(Looper.java:137)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.app.ActivityThread.main(ActivityThread.java:4931)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at java.lang.reflect.Method.invokeNative(Native Method)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at java.lang.reflect.Method.invoke(Method.java:511)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at dalvik.system.NativeStart.main(Native Method)
11-16 15:06:37.255: E/AndroidRuntime(15193): Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.model.engine
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Parcel.readParcelable(Parcel.java:2077)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Parcel.readValue(Parcel.java:1965)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Parcel.readMapInternal(Parcel.java:2226)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Bundle.unparcel(Bundle.java:223)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at android.os.Bundle.getString(Bundle.java:1055)
11-16 15:06:37.255: E/AndroidRuntime(15193):         at com.example.cars.CarPresenter.getExtraString(CarPresenter.java:34)
11-16 15:06:37.255: E/AndroidRuntime(15193):         ... 11 more

So it somehow fails to read anything from the Bundle.

This can be solved by modifying the readBundle call to:

  public Car(Parcel parcel) {    
    getPresenter().setBundle(parcel.readBundle(engine.class.getClassLoader()));
  }

However, wouldn’t this mean that I could only have one type of parcelables in my bundle? For example, what if another presenter wanted to add another parcelable object to the bundle?

Could anyone shed some light on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:06:25+00:00Added an answer on June 14, 2026 at 7:06 pm

    You wrote in a comment:

    However, my question was ment to be more of why do I even have to specify a class loader in this case

    Dianne Hackborn, Android framework engineer, writes that:

    when the bundle reads from the parcel it just extracts the data. It doesn’t actually unparcel from that data until later when you retrieve stuff from the bundle.

    In the Bundle source code, we see that the setClassLoader()method sets the field mClassLoader:

    public void setClassLoader(ClassLoader loader) {
         mClassLoader = loader;
     }
    

    If we don’t use setClassLoader() or the constructor Bundle(ClassLoader loader),the mClassLoader field will be set to the default ClassLoader:

    public Bundle(int capacity) {
         //...
         mClassLoader = getClass().getClassLoader();
     }
    

    mClassLoader is then used to unmarshal the parcelled data in the unparcel() method:

     mParcelledData.readMapInternal(mMap, N, mClassLoader);
     mParcelledData.recycle();
     mParcelledData = null;
    

    Net, if you don’t set the ClassLoader it will default to the system ClassLoader when unmarshalling its parcelled data, and we’ll get a ClassNotFoundException when unmarshalling our custom Parcelable object data,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a project model which has many members and many tasks.
I have a project which exposes object model to use by different types of
Suppose I have got a model ArticleVersion in my project which is defined as:
I have an old Xcode project which contains a CoreData model (containing a version
Let's say I have a model class called Project, but instead of this: class
With a PHP MVC project, I have a few model classes that load data
I have been tasked with refactoring a project that currently uses an EAV model
I have a Project model and a Task model. say in my controller I
I have a Project model which accepts nested attributes for tasks. And Task has
In my Symfony2 project, I have a ModelBundle which holds my entities, and other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.