无法从Fragment转向活动

时间:2016-10-04 13:06:05

标签: android android-fragments

我已经从代码中添加了片段,并在创建时将数据从活动传递到片段,现在当我编写代码时,意图将片段转移到其他一些活动我得到了... java.lang.RuntimeException:Parcel :无法编组值

这是我在我的Main类中用来创建片段的代码

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

这是实际的Fragment类

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

现在在OnCreateView中,当我使用intent移动到另一个活动时,它给出java.lang.RuntimeException:Parcel:无法编组值

这是日志

  

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

1 个答案:

答案 0 :(得分:1)

您的Data对象不可序列化。

public class Data implements Serializable{

}

选中link