Serializable报错问题,java.lang.RuntimeException: Parce
2015-04-10 00:00
260 查看
代码中使用Parcel在两个Activity中进行数据传送,Parcel需要实现Parcelable接口。而如果在Parcel类中,需要读或者写其他的bean数据的话,这些bean需要实现Serializable序列化接口。不然会出现java.lang.RuntimeException: Parcel: unable to marshal value错误!
而没有没有实现Serializable时会出现错误。
修改方法是需要在所调用的类中实现Serializable。
参考了如下文章:
http://blog.csdn.net/huim_lin/article/details/16959865
public static ProgramInformationFragment newInstance(List<ChannelItem> items) { ProgramInformationFragment fragment = new ProgramInformationFragment(); Bundle args = new Bundle(); //将items作为Serializable传到bundle args.putSerializable(KEY_PROGRAM_ITEMS, (Serializable) items); fragment.setArguments(args); return fragment; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getArguments() != null) { mProgramItems = (ArrayList<ChannelItem>) getArguments().getSerializable(KEY_PROGRAM_ITEMS); Logger.i("lfj mProgramItems.size = " + mProgramItems.size()); } }
而没有没有实现Serializable时会出现错误。
04-10 12:12:01.616 7702-7702/**.**.android.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Parcel: unable to marshal value jp.nhkworldtv.android.model.ChannelItem@41b981a0 at android.os.Parcel.writeValue(Parcel.java:1137) at android.os.Parcel.writeList(Parcel.java:524) at android.os.Parcel.writeValue(Parcel.java:1097) at android.os.Parcel.writeMapInternal(Parcel.java:493) at android.os.Bundle.writeToParcel(Bundle.java:1612) at android.os.Parcel.writeBundle(Parcel.java:507) at android.support.v4.app.FragmentState.writeToParcel(Fragment.java:136) at android.os.Parcel.writeTypedArray(Parcel.java:1004) at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:383) at android.os.Parcel.writeParcelable(Parcel.java:1156) at android.os.Parcel.writeValue(Parcel.java:1075) at android.os.Parcel.writeMapInternal(Parcel.java:493) at android.os.Bundle.writeToParcel(Bundle.java:1612) at android.os.Parcel.writeBundle(Parcel.java:507) at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2016) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2880) at android.app.ActivityThread.access$900(ActivityThread.java:128) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1175) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4514) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) at dalvik.system.NativeStart.main(Native Method)
修改方法是需要在所调用的类中实现Serializable。
public class ChannelItem implements Serializable{ /** * シリアル。 */ private static final long serialVersionUID = 1L; private String mSeriesId; private String mAiringId; . . .
参考了如下文章:
http://blog.csdn.net/huim_lin/article/details/16959865
相关文章推荐
- Fragment内部控件操作的E/AndroidRuntime(1778): java.lang.NullPointerException问题解决
- storm中使用log出现java.lang.RuntimeException: java.io.NotSerializableException: java.util.logging.Logger
- java.lang.RuntimeException:Picasso detected an unsupported OkHttp on the classpath 问题
- 【安卓学习问题日志】java.lang.RuntimeException: Unable to start activity ComponentInfo{org.wm.demo/org.wm.demo
- Android—子线程更新UI问题( java.lang.RuntimeException: Can't create handler inside thread that has not cal)
- Android 访问Webservice接口,参数对象不能串行化问题解决(java.lang.RuntimeException: Cannot serialize)
- checkstyle问题:解决Got an exception - java.lang.RuntimeException: Unable to get class information for ***Exception
- Android-java.lang.RuntimeException: Package manager has died问题
- java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable obje
- 解决java.lang.RuntimeException: Unable to start activity Activity无法打开的问题
- 严重: Dispatcher initialization failed java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 问题解决
- Android问题:Test run failed: Instrumentation run failed due to 'java.lang.RuntimeException'
- Storm 执行异常 java.lang.RuntimeException: java.nio.channels.UnresolvedAddressException 问题解决
- java.lang.RuntimeException: Parcelable encountered IOException writing serializable object
- 工具问题——再次手贱,报:java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
- Drools 运行时出现Exception in thread "main" java.lang.RuntimeException: wrong class format 的问题
- 开发问题及解决 E/AndroidRuntime(15377): Caused by: java.lang.InstantiationException: can't instantiate clas
- resin WED服务器初用遇到的问题和解决方法 java.lang.RuntimeException: java.net.SocketException: Unrecognized Windows Socke ts error: 0: JVM_Bind
- Myeclipse下配置SVN报错问题 svn: E175002: java.lang.RuntimeException: Could not generate DH keypair(转)
- java.lang.RuntimeException: Parcelable encountered IOException writing serializable object