0

I have added fragment from code and passed data from activity to fragment when they are created ,now when i write the code to intent away from that fragments to some other activity Im getting the...java.lang.RuntimeException: Parcel: unable to marshal value

This is the code I'm using in my Main class to create Fragments

Log.e("list=",data.toString());
fragments.add(MyFragment.newInstance(data,values.toString(),response1));
data=new ArrayList<>();
pageAdapter=new MyPageAdapter(getSupportFragmentManager(),fragments);
pager.setAdapter(pageAdapter);

This is the actual Fragment class

public class MyFragment extends Fragment   {
    public static final String EXTRA_MESSAGE = "EXTRA_MESSAGE";
    public static final String EXTRA_MESSAGE1 = "Check";
    public static final String EXTRA_MESSAGE2 = "Check1";
    String order_id;
    private ProgressDialog pDialog;
    SwipeMenuListView listView;

    public static final MyFragment newInstance(List<Data> data,String check,String response)
    {
        MyFragment f = new MyFragment();
        Bundle bdl = new Bundle(3);
        bdl.putSerializable(EXTRA_MESSAGE, (Serializable) data);
        bdl.putString(EXTRA_MESSAGE1, check);
        bdl.putString(EXTRA_MESSAGE2, response);
        f.setArguments(bdl);
        return f;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        List<Data> message = (List<Data>) getArguments().getSerializable(EXTRA_MESSAGE);
        final String show = getArguments().getString(EXTRA_MESSAGE1);
        final String responseaa=getArguments().getString(EXTRA_MESSAGE2);
    }
}

Now in OnCreateView ,when Im using intent to move to another activity it is giving java.lang.RuntimeException: Parcel: unable to marshal value

This is the log

java.lang.RuntimeException: Parcel: unable to marshal value com.sindhibandhan.digitalstrikers.dynamicfragement.Data@30898801 at android.os.Parcel.writeValue(Parcel.java:1337) at android.os.Parcel.writeList(Parcel.java:711) at android.os.Parcel.writeValue(Parcel.java:1284) at android.os.Parcel.writeArrayMapInternal(Parcel.java:638) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313) at android.os.Bundle.writeToParcel(Bundle.java:1096) at android.os.Parcel.writeBundle(Parcel.java:663) at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:142) at android.os.Parcel.writeTypedArray(Parcel.java:1191) at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:396) at android.os.Parcel.writeParcelable(Parcel.java:1357) at android.os.Parcel.writeValue(Parcel.java:1262) at android.os.Parcel.writeArrayMapInternal(Parcel.java:638) at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313) at android.os.Bundle.writeToParcel(Bundle.java:1096) at android.os.Parcel.writeBundle(Parcel.java:663) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2992) at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3450) at android.os.Handler.handleCallback(Handler.java:810) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:189) at android.app.ActivityThread.main(ActivityThread.java:5529) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)

Komal12
  • 3,340
  • 4
  • 16
  • 25

1 Answers1

1

Your Data object is not serializable.

public class Data implements Serializable{

}

Check this link.

Community
  • 1
  • 1
suku
  • 10,507
  • 16
  • 75
  • 120
  • You are asking about the main class ,in this case ? – Raman Bhayana Oct 05 '16 at 03:18
  • You have created an object class having the name Data...do this over there – suku Oct 05 '16 at 03:37
  • 1
    Thank you so much, I've been fighting with this all day, tested with Parcelables and nothing, but this answers works great, I thought that was the serializable because of the use of the annotations but clearly I was wrong, thanks. – Kevin Ramirez Zavalza Jun 12 '18 at 01:55