问题描述
我有几个崩溃报告日志从Android Market类似这样:
I have a few crash report logs from android market similar to this:
Exception class: java.lang.ClassNotFoundException
Source method: PathClassLoader.findClass()
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.app.package/my.app.package.MyActivity}: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = my.app.package.a.ae)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2833)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2854)
at android.app.ActivityThread.access$2300(ActivityThread.java:136)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2179)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:5068)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Parcelable encounteredClassNotFoundException reading a Serializable object (name = my.app.package.a.ae)
at android.os.Parcel.readSerializable(Parcel.java:1951)
at android.os.Parcel.readValue(Parcel.java:1822)
at android.os.Parcel.readMapInternal(Parcel.java:2008)
at android.os.Bundle.unparcel(Bundle.java:208)
at android.os.Bundle.getBundle(Bundle.java:1078)
at android.app.Activity.onRestoreInstanceState(Activity.java:861)
at android.app.Activity.performRestoreInstanceState(Activity.java:835)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2811)
... 11 more
Caused by: java.lang.ClassNotFoundException: my.app.package.a.ae
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:235)
at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2590)
at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1846)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:826)
at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:2066)
at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:929)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2285)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2240)
at android.os.Parcel.readSerializable(Parcel.java:1945)
... 19 more
Caused by: java.lang.NoClassDefFoundError: my.app.package.a.ae
... 29 more
Caused by: java.lang.ClassNotFoundException: my.app.package.a.ae in loader dalvik.system.PathClassLoader[.]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
... 29 more
请注意,我用的ProGuard - >这就是为什么失踪类的名字是a.ae
。实际上,a.ae这个名字proguard的给了类MyObject的,这将在下面示出。
Please note that I am using proguard -> that's why the "missing" class name is "a.ae".
Actually, "a.ae" is the name proguard gave to the class "MyObject", which is shown below.
这是为什么发生这种情况的任何IDEIA?
Any ideia on why this happens?
我不认为它必须与ProGuard的,因为如果它造成的ProGuard类重命名一个问题,它应该发生任何时候,我将能够重现这个问题我自己。
I don't think it has to do with proguard, because if it was a problem caused by proguard class renaming, it should happen all times and I would be able to reproduce this issue myself.
是否都与传递序列化对象MyActivity?
在MyActivity我已经
Does it have to do with passing a serializable object to MyActivity?
In MyActivity I have
public void onCreate(Bundle savedInstanceState) {
myObj = (MyObject) getIntent().getSerializableExtra("nameOfMyObject");
//here I am trying to read myObj's properties and app seems to crash here
}
为MyObject只是用几种类型的类成员,前一个实体:
公共类为MyObject实现Serializable {
MyObject is just an entity with several types of class members, ex:
public class MyObject implements Serializable {
/** Generated serialVersionUID */
static final long serialVersionUID = -267025879233327409L;
static final String CONSTANT1 = "xpto";
LinkedHashMap<String, Object> components;
ArrayList<String> prop1;
(...)
}
我开始MyActivity有:
I am starting MyActivity with:
MyObject obj = new MyObj(stuff);
Intent intent;
intent = new Intent(CurrentActivity.this, MyActivity.class);
intent.putExtra("nameOfMyObject", obj);
CurrentActivity.this.startActivity(intent);
你觉得它做的目的是传递(作为一个额外的序列化)的方法是什么?
在我没有找到任何其他解决方案,我想我会序列化的对象自己String,然后通过额外的字符串的情况下。你怎么看这件事?
Do you think it has to do with the way the object is being passed (as a serializable extra)?
In the case that I don't find any other solution I think I will "serialize" the object myself to a String and then pass the String extra.What do you think about this?
编辑:我试图重现此问题,没有成功,在模拟器和以下设备:
I have tried to reproduce this issue, without success, in the emulator and in the following devices:
-motorola里程碑2的Android 2.2
-Samsung的Galaxy Tab的Android 2.2
-Vodafone 845的Android 2.1
-HTC刺青的Android 1.6
-Xperia X10的Android 1.6
-Nexus一个Android 2.2的
- 谷歌G1的Android 1.5
-Motorola Milestone 2 Android 2.2
-Samsung Galaxy Tab Android 2.2
-Vodafone 845 Android 2.1
-HTC Tatoo Android 1.6
-Xperia X10 Android 1.6
-Nexus One Android 2.2
-Google G1 Android 1.5
什么新的想法?
推荐答案
终于就这一问题得出结论:它被引起的Proguard的,或者更具体地说,是因为我没有一个propper Proguard的配置。
Finally reached a conclusion on this issue: it was being caused by Proguard, or more specifically, because I didn't have a propper Proguard configuration.
原来Proguard的是改变我的序列化
的类名,这让的Class.forName(类名)
失败。
It turns out Proguard was changing my Serializable
's classes names, which makes Class.forName(className)
fail.
我不得不重新配置我的 proguard.cfg
文件中添加以下行:
I had to reconfigure my proguard.cfg
file adding the following lines:
-keep class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
!private <fields>;
!private <methods>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
这篇关于安卓:ClassNotFoundException的传递序列化的对象到活动时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!