我试着把一个PARCELLID对象写在一个PARCELLID对象上,但是我得到了一个Java运行时错误,说“unSunScLeunle中没有发现类”。
洛卡特
11-13 08:41:06.412: E/Parcel(791): Class not found when unmarshalling: com.firstandroidapp.EventMeta
11-13 08:41:06.412: E/Parcel(791): java.lang.ClassNotFoundException: com.firstandroidapp.EventMeta
11-13 08:41:06.412: E/Parcel(791): at java.lang.Class.classForName(Native Method)
11-13 08:41:06.412: E/Parcel(791): at java.lang.Class.forName(Class.java:204)
11-13 08:41:06.412: E/Parcel(791): at java.lang.Class.forName(Class.java:169)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readParcelableCreator(Parcel.java:2091)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readParcelable(Parcel.java:2055)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readValue(Parcel.java:1971)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readListInternal(Parcel.java:2264)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readList(Parcel.java:1537)
11-13 08:41:06.412: E/Parcel(791): at com.firstandroidapp.EventHolder.<init>(EventHolder.java:36)
11-13 08:41:06.412: E/Parcel(791): at com.firstandroidapp.EventHolder$1.createFromParcel(EventHolder.java:17)
11-13 08:41:06.412: E/Parcel(791): at com.firstandroidapp.EventHolder$1.createFromParcel(EventHolder.java:1)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readParcelable(Parcel.java:2062)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readValue(Parcel.java:1971)
11-13 08:41:06.412: E/Parcel(791): at android.os.Parcel.readMapInternal(Parcel.java:2255)
11-13 08:41:06.412: E/Parcel(791): at android.os.Bundle.unparcel(Bundle.java:223)
11-13 08:41:06.412: E/Parcel(791): at android.os.Bundle.getParcelable(Bundle.java:1170)
11-13 08:41:06.412: E/Parcel(791): at android.content.Intent.getParcelableExtra(Intent.java:4501)
11-13 08:41:06.412: E/Parcel(791): at com.firstandroidapp.AddSubjectFragment.onActivityResult(AddSubjectFragment.java:198)
11-13 08:41:06.412: E/Parcel(791): at android.support.v4.app.FragmentActivity.onActivityResult(FragmentActivity.java:166)
11-13 08:41:06.412: E/Parcel(791): at android.app.Activity.dispatchActivityResult(Activity.java:5322)
11-13 08:41:06.412: E/Parcel(791): at android.app.ActivityThread.deliverResults(ActivityThread.java:3363)
11-13 08:41:06.412: E/Parcel(791): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410)
11-13 08:41:06.412: E/Parcel(791): at android.app.ActivityThread.access$1100(ActivityThread.java:141)
11-13 08:41:06.412: E/Parcel(791): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
11-13 08:41:06.412: E/Parcel(791): at android.os.Handler.dispatchMessage(Handler.java:99)
11-13 08:41:06.412: E/Parcel(791): at android.os.Looper.loop(Looper.java:137)
11-13 08:41:06.412: E/Parcel(791): at android.app.ActivityThread.main(ActivityThread.java:5103)
11-13 08:41:06.412: E/Parcel(791): at java.lang.reflect.Method.invokeNative(Native Method)
11-13 08:41:06.412: E/Parcel(791): at java.lang.reflect.Method.invoke(Method.java:525)
11-13 08:41:06.412: E/Parcel(791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11-13 08:41:06.412: E/Parcel(791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-13 08:41:06.412: E/Parcel(791): at dalvik.system.NativeStart.main(Native Method)
11-13 08:41:06.412: E/Parcel(791): Caused by: java.lang.NoClassDefFoundError: com/firstandroidapp/EventMeta
11-13 08:41:06.412: E/Parcel(791): ... 32 more
11-13 08:41:06.412: E/Parcel(791): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.firstandroidapp.EventMeta" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/system/lib]]
11-13 08:41:06.412: E/Parcel(791): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
11-13 08:41:06.412: E/Parcel(791): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-13 08:41:06.412: E/Parcel(791): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-13 08:41:06.412: E/Parcel(791): ... 32 more
据我所知,在将
EventMeta
列表写入EventHolder
时发生错误。下面是
EventHolder
和EventMeta
的实现。小精灵
public class EventHolder implements Parcelable {
public List<EventMeta> mEMList = new ArrayList<EventMeta>();
public Event mEvent;
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public EventHolder createFromParcel(Parcel in) {
return new EventHolder(in);
}
public EventHolder[] newArray(int size) {
return new EventHolder[size];
}
};
public EventHolder(List<EventMeta> mEMList, Event mEvent) {
this.mEMList = mEMList;
this.mEvent = mEvent;
}
public EventHolder(Parcel in){
mEMList= new ArrayList<EventMeta>();
in.readTypedList(mEMList, EventMeta.CREATOR);
this.mEvent = in.readParcelable(null);
}
public int describeContents(){
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeTypedList(mEMList);
dest.writeParcelable(mEvent, flags);
}
}
事件元
public class EventMeta implements Parcelable {
long mEventMetaId;
long mEventId;
Date mStartDate;
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public EventMeta createFromParcel(Parcel in) {
return new EventMeta(in);
}
public EventMeta[] newArray(int size) {
return new EventMeta[size];
}
};
public EventMeta(long mEventMetaId, long mEventId, Date mStartDate) {
this.mEventMetaId = mEventMetaId;
this.mEventId = mEventId;
this.mStartDate = mStartDate;
}
public EventMeta(Parcel in) {
this.mEventMetaId = in.readLong();
this.mEventId = in.readLong();
this.mStartDate = new Date(in.readLong());
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.mEventMetaId);
dest.writeLong(this.mEventId);
dest.writeLong(this.mStartDate.getTime());
}
}
我的代码有什么问题吗?我在发帖前仔细检查了一下,但找不到任何不合适的地方。
最新更新
我使用了daneejela的答案,现在问题转移到了名为“class”的类,这意味着问题已经部分解决了。
Class
扩展“事件,它如下所示:public class Class extends Event {
long mClassId;
String mClassLocation;
long mSubjectId;
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Class createFromParcel(Parcel in) {
return new Class(in);
}
public Class[] newArray(int size) {
return new Class[size];
}
};
public Class(long mClassId, String location, long mSubjectId, long mEventId, int mEventPriority, String mEventTitle, String mEventNotes, long start, long end) {
super(mEventId, mEventPriority, mEventTitle, mEventNotes, start, end);
this.mClassId = mClassId;
this.mClassLocation = location;
this.mSubjectId = mSubjectId;
}
public Class(Parcel in){
super(in);
this.mClassId = in.readLong();
this.mClassLocation = in.readString();
this.mSubjectId = in.readLong();
}
public int describeContents(){
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeLong(this.mClassId);
dest.writeString(this.mClassLocation);
dest.writeLong(this.mSubjectId);
}
}
更新2
事件
public class Event implements Parcelable {
long mEventId;
int mEventPriority;
String mEventTitle;
String mEventNotes;
long mEventStartTime;
long mEventEndTime;
@SuppressWarnings("rawtypes")
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Event createFromParcel(Parcel in) {
return new Event(in);
}
public Event[] newArray(int size) {
return new Event[size];
}
};
public Event(long id, int priority, String title, String notes, long start, long end) {
this.mEventId = id;
this.mEventPriority = priority;
this.mEventTitle = title;
this.mEventNotes = notes;
this.mEventStartTime = start;
this.mEventEndTime = end;
}
public Event(Parcel in){
this.mEventId = in.readLong();
this.mEventPriority = in.readInt();
this.mEventTitle = in.readString();
this.mEventNotes = in.readString();
this.mEventStartTime = in.readLong();
this.mEventEndTime = in.readLong();
}
public int describeContents(){
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(this.mEventId);
dest.writeInt(this.mEventPriority);
dest.writeString(this.mEventTitle);
dest.writeString(this.mEventNotes);
dest.writeLong(this.mEventStartTime);
dest.writeLong(this.mEventEndTime);
}
}
最佳答案
尝试此代码
公共类eventholder实现parcelable{
public list memlist=new arrayList();
公共事件;
public static final parcelable.creator creator=新建parcelable.creator(){
公共事件持有者CreateFromParcel(Parcel-In){
返回新的事件持有者(in);
}
public eventholder[]newarray(int size){
返回新的事件持有者[大小];
}
};
公共事件持有者(列表memlist,事件mevent){
this.memlist=memlist;
this.mevent=mevent;
}
公共事件持有者(包裹输入){
in.readlist(memlist,memlist.getclass().getclassloader());
this.mevent=in.readParcelable(mevent.getClass().getClassloader());
}
公共int descripbecontents(){
返回0xFE;
}
public void writeToParcel(包目的地,int标志){
目标写入列表(memlist);
目的地可写(mevent,describeContents());
}
}
我怀疑这件事是否可以解决?
如果不是这样的话。