我正在构建一个Android小部件,我尝试为小部件中的每个列表项添加点击功能。 它工作,但我只是不知何故不能把意图的额外的东西。当我尝试将我的类Parallel放在那里实现Parcalable接口时,它会因为跟随错误而失败。是否有可能小部件本身无法访问该类? (它位于我的Apps命名空间及其公开内容)
10-01 11:13:50.819 18503-18809/? E/Parcel﹕ Class not found when unmarshalling: cz.cvut.kosapp.model.entities.Parallel
java.lang.ClassNotFoundException: cz.cvut.kosapp.model.entities.Parallel
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:204)
at java.lang.Class.forName(Class.java:169)
at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
at android.os.Parcel.readParcelable(Parcel.java:2055)
at android.os.Parcel.readValue(Parcel.java:1971)
at android.os.Parcel.readMapInternal(Parcel.java:2255)
at android.os.Bundle.unparcel(Bundle.java:223)
at android.os.Bundle.putAll(Bundle.java:302)
at android.content.Intent.fillIn(Intent.java:6352)
at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:210)
at com.android.server.am.ActivityManagerService.startActivityIntentSender(ActivityManagerService.java:2603)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:232)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1737)
at android.os.Binder.execTransact(Binder.java:388)
at dalvik.system.NativeStart.run(Native Method)
Caused by: java.lang.NoClassDefFoundError: cz/cvut/kosapp/model/entities/Parallel
... 16 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "cz.cvut.kosapp.model.entities.Parallel" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
... 16 more
答案 0 :(得分:0)
对于Parcelable
,有时会出现一个奇怪的问题,即它无法在进程之间找到类,也许这里有人可以提醒我原因。在您的Parallel
模型对象中,您传递的应该添加一个显式调用getClassLoader()
。
所以这样......
protected Parallel(Parcel source) {
super(source);
// Explicitly get the class loader of this class as there is sometimes a
// weird issue
// when passing Parcel between processes
Bundle data = source.readBundle(Parallel.class.getClassLoader());
this.foo = data.getLong("foo");
this.bar = data.getString("bar");
}