Amit0191
Amit0191

Reputation: 109

android.os.BadParcelableException: ClassNotFoundException when unmarshalling:

I have no idea why this is happening and I am unable to reproduce it. It is in the console.

I am really sorry for just putting in the code and log cat but I can't even read the logcat, I haven't encountered such a problem earlier and I don't even know where to begin with. Any help would be greatly appreciated.

This is the log cat,

android.os.BadParcelableException: ClassNotFoundException when unmarshalling: bitsie.playmee.musicplayer.free.classes.SongDetails
    at android.os.Parcel.readParcelableCreator(Parcel.java:2147)
    at android.os.Parcel.readParcelable(Parcel.java:2097)
    at android.os.Parcel.readValue(Parcel.java:2013)
    at android.os.Parcel.readListInternal(Parcel.java:2343)
    at android.os.Parcel.readArrayList(Parcel.java:1703)
    at android.os.Parcel.readValue(Parcel.java:2034)
    at android.os.Parcel.readArrayMapInternal(Parcel.java:2314)
    at android.os.Bundle.unparcel(Bundle.java:249)
    at android.os.Bundle.getSparseParcelableArray(Bundle.java:1273)
    at android.support.v4.app.FragmentManagerImpl.throwException(Unknown Source)
                                                  beginTransaction
                                                  putFragment
                                                  getFragment
                                                  saveFragmentInstanceState
                                                  dump
                                                  makeOpenCloseAnimation
                                                  makeFadeAnimation
                                                  loadAnimation
                                                  moveToState
                                                  moveToState
                                                  moveToState
                                                  addFragment
                                                  removeFragment
                                                  findFragmentById
                                                  findFragmentByTag
                                                  enqueueAction
                                                  allocBackStackIndex
                                                  setBackStackIndex
                                                  popBackStackState
                                                  restoreAllState
                                                  attachActivity
                                                  dispatchConfigurationChanged
                                                  dispatchCreateOptionsMenu
                                                  dispatchPrepareOptionsMenu
                                                  dispatchOptionsItemSelected
    at android.support.v4.app.FragmentManagerImpl.throwException(Unknown Source)
                                                  beginTransaction
                                                  putFragment
                                                  getFragment
                                                  saveFragmentInstanceState
                                                  dump
                                                  makeOpenCloseAnimation
                                                  makeFadeAnimation
                                                  loadAnimation
                                                  moveToState
                                                  moveToState
                                                  moveToState
                                                  addFragment
                                                  removeFragment
                                                  findFragmentById
                                                  findFragmentByTag
                                                  enqueueAction
                                                  allocBackStackIndex
                                                  setBackStackIndex
                                                  popBackStackState
                                                  restoreAllState
                                                  attachActivity
                                                  dispatchConfigurationChanged
                                                  dispatchCreateOptionsMenu
                                                  dispatchPrepareOptionsMenu
                                                  dispatchOptionsItemSelected
    at android.support.v4.app.BackStackRecord.run(Unknown Source)
    at android.support.v4.app.FragmentManagerImpl.makeInactive(Unknown Source)
                                                  attachFragment
                                                  execPendingActions
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(Unknown Source)
                                                  performPendingDeferredStart
                                                  hideFragment
                                                  freeBackStackIndex
                                                  addBackStackState
                                                  dispatchContextItemSelected
                                                  dispatchOptionsMenuClosed
                                                  transitToStyleIndex
    at android.support.v4.app.FragmentStatePagerAdapter.setPrimaryItem(Unknown Source)
                                                        finishUpdate
    at android.support.v4.view.ViewPager.initViewPager(Unknown Source)
                                         setCurrentItem
                                         setCurrentItemInternal
                                         setCurrentItemInternal
                                         scrollToItem
                                         setPageTransformer
                                         setInternalPageChangeListener
                                         distanceInfluenceForSnapDuration
                                         smoothScrollTo
                                         addNewItem
                                         populate
                                         calculatePageOffsets
                                         infoForChild
                                         recomputeScrollPosition
                                         onPageScrolled
                                         completeScroll
                                         isGutterDrag
                                         determineTargetPage
                                         onSecondaryPointerUp
                                         canScroll
                                         executeKeyEvent
                                         getChildRectInPagerCoordinates
                                         access$000
                                         access$200
    at android.support.v4.view.ViewPager.populate(Unknown Source)
                                         requestParentDisallowInterceptTouchEvent
                                         arrowScroll
    at android.support.v4.view.ViewPager$3.run(Unknown Source)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    at android.view.Choreographer.doFrame(Choreographer.java:543)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5111)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
    at dalvik.system.NativeStart.main(Native Method)

And here is the code of the class

public class SongDetails implements Parcelable
{


    public SongDetails( int _ID, String click_no, String Album, String Artist, String Path, String Time, String song, String sortBy, int albumID,
            String audioID )
    {
        this._ID = _ID;
        this.click_no = click_no;
        this.Album = Album;
        this.Artist = Artist;
        this.Path = Path;
        this.Time = Time;
        this.song = song;
        this.sortBy = sortBy;
        this.albumID = albumID;
        this.audioID = audioID;
    }


    public SongDetails( Parcel in )
    {
        this._ID = in.readInt( );
        this.Path = in.readString();
        this.song = in.readString( );
        this.Album = in.readString( );
        this.Artist = in.readString( );
        this.Time = in.readString( );
        this.sortBy = in.readString( );
        this.click_no = in.readString( );
        this.albumID = Integer.parseInt( in.readString( ) );
        this.audioID = in.readString( );
    }


    @Override
    public int describeContents( )
    {
        return 0;
    }

    @Override
    public void writeToParcel( Parcel dest, int flags )
    {
        dest.writeInt( _ID );
        dest.writeString( Path );
        dest.writeString( song );
        dest.writeString( Album );
        dest.writeString( Artist );
        dest.writeString( Time );
        dest.writeString( sortBy );
        dest.writeString( click_no );
        dest.writeString( String.valueOf( albumID ) );
        dest.writeString( audioID );
    }

    public static final Parcelable.Creator < SongDetails > CREATOR = new Parcelable.Creator < SongDetails >( ) {
        public SongDetails createFromParcel( Parcel in )
        {
            return new SongDetails( in );
        }

        public SongDetails [ ] newArray( int size )
        {
            return new SongDetails [ size ];
        }
    };
}

activity code, where the parcelable data is being read

Bundle bundle = getIntent( ).getExtras( );
    if ( bundle != null )
    {
        if ( GlobalSongList.GetInstance( ).getCheck( ) == 0 )
        {
            try
            {
                GlobalSongList.GetInstance( ).setPosition( bundle.getInt( "Data2", 0 ) );
                if(bundle.getParcelableArrayList( "Data1" )!=null)
                {
                    ArrayList < SongDetails > list = 

bundle.getParcelableArrayList( "Data1" );
                        GlobalSongList.GetInstance( ).SetNowPlayingList( list );

                    }
                    CMDNAME = bundle.getString( IConstant.CMDNAME );
                }
                catch ( Exception e )
                {
                    // e.printStackTrace( );
                }
            }
            comefrom = bundle.getString( "comefrom" );
            isFromRecentAdded = bundle.getBoolean( "fromRecentAdded", false );
            click_no = bundle.getString( "click_no_playlist" );

Upvotes: 2

Views: 6281

Answers (1)

antonio
antonio

Reputation: 18252

I think that the problem is that you are not setting the class loader when unmarshalling the SongDetailslist.

You can do the following to read "Data1":

if(bundle.getParcelableArrayList( "Data1" )!=null) {
    bundle.setClassLoader (SongDetails.class.getClassLoader());
    ArrayList < SongDetails > list = bundle.getParcelableArrayList( "Data1" );

    // Rest of your code
}

Upvotes: 4

Related Questions