传递Serializable时ClassNotFoundException

时间:2013-03-19 14:30:45

标签: android serialization bundle

我是Android开发人员,我正在尝试使用SerializableActivity个对象发送给另一个Bundle。但是,我得到以下内容 - Parcelable encountered ClassNotFoundException reading a Serializable object为错误。

这是什么原因以及如何解决?

以下是代码段:

Bundle previousData = new Bundle();
previousData.putSerializable("GetVehicleInfo_AllTrims", trimsObj);// trimObj is a serialized object
Intent detailsIntent = new Intent(androidScrolbleTabbar.TABBAR_PUSHVIEW);
detailsIntent.putExtras(previousData);
detailsIntent.putExtra("ActivityIdentifier", ManualScreenNav2.viewIdentifier);
detailsIntent.putExtra("className", ManualScreenNav2.class.getName());
sendBroadcast(detailsIntent);

以下是完整的堆栈跟踪:

03-19 15:39:02.549: E/AndroidRuntime(27084): FATAL EXCEPTION: main
03-19 15:39:02.549: E/AndroidRuntime(27084): java.lang.RuntimeException: Error receiving broadcast Intent { act=com.mobyfactory.pushview (has extras) } in com.adplotmanagement.androidScrolbleTabbar$PUSHViewBroadcastReceiver@461bc340
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:942)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Handler.handleCallback(Handler.java:587)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Looper.loop(Looper.java:143)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.app.ActivityThread.main(ActivityThread.java:4701)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.reflect.Method.invokeNative(Native Method)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.reflect.Method.invoke(Method.java:521)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at dalvik.system.NativeStart.main(Native Method)
03-19 15:39:02.549: E/AndroidRuntime(27084): Caused by: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Parcel.readSerializable(Parcel.java:1951)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Parcel.readValue(Parcel.java:1822)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Parcel.readMapInternal(Parcel.java:2008)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Bundle.unparcel(Bundle.java:208)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Bundle.getString(Bundle.java:1034)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at com.adplotmanagement.androidScrolbleTabbar$PUSHViewBroadcastReceiver.onReceive(androidScrolbleTabbar.java:560)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.app.ActivityThread$PackageInfo$ReceiverDispatcher$Args.run(ActivityThread.java:910)
03-19 15:39:02.549: E/AndroidRuntime(27084):    ... 9 more
03-19 15:39:02.549: E/AndroidRuntime(27084): Caused by: java.lang.ClassNotFoundException: com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.Class.classForName(Native Method)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.Class.forName(Class.java:235)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2590)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1846)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:826)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2066)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at android.os.Parcel.readSerializable(Parcel.java:1945)
03-19 15:39:02.549: E/AndroidRuntime(27084):    ... 15 more
03-19 15:39:02.549: E/AndroidRuntime(27084): Caused by: java.lang.NoClassDefFoundError: com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims
03-19 15:39:02.549: E/AndroidRuntime(27084):    ... 25 more
03-19 15:39:02.549: E/AndroidRuntime(27084): Caused by: java.lang.ClassNotFoundException: com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.adplotmanagement-1.apk]
03-19 15:39:02.549: E/AndroidRuntime(27084):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
03-19 15:39:02.549: E/AndroidRuntime(27084):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
03-19 15:39:02.549: E/AndroidRuntime(27084):    ... 25 more

错过了再加一点,我有两个具有相同功能的应用程序,每个应用程序具有相同的类GetVehicleInfo_AllTrims,它是一个pojo类。当我在前台运行一个应用程序时,生活在后台的另一个应用程序因上述错误而崩溃。

2 个答案:

答案 0 :(得分:2)

您好找到问题的根本原因并解决了问题。

在两个应用中,我们使用相同的BroadCastReceivers及其intent过滤器。由于此问题,运行时无法为应用程序找到合适的接收器。

我修改了两个应用程序的intent过滤器,现在工作正常。

答案 1 :(得分:0)

java.lang.ClassNotFoundException: com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims
  

这是什么原因

造成这种情况的原因是未找到类com.halcyon.ui.redbumper.entities.RBGetVehicleInfoByVin_AllTrims

  

我该如何解决?

在应用程序的CLASSPATH上使该类可用。