0
我做的,我有存儲/恢復數據是JavaMail的消息的HashMap的,但我收到以下錯誤Android應用程序:傳遞的JavaMail消息的HashMap來Android的活動
02-20 08:11:25.650: E/AndroidRuntime(2264): FATAL EXCEPTION: main
02-20 08:11:25.650: E/AndroidRuntime(2264): java.lang.RuntimeException: Parcel: unable to marshal value [email protected]
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeValue(Parcel.java:1235)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeArray(Parcel.java:641)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeValue(Parcel.java:1220)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeMapInternal(Parcel.java:591)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeMap(Parcel.java:575)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeValue(Parcel.java:1166)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeMapInternal(Parcel.java:591)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Bundle.writeToParcel(Bundle.java:1627)
02-20 08:11:25.650: E/AndroidRuntime(2264): at android.os.Parcel.writeBundle(Parcel.java:605)
02-20 08:11:25.650: E/AndroidRuntime(2264): at com.example.androidtablayout.SimpleParcelable.writeToParcel(SimpleParcelable.java:57)
</code>
MailActivity.java
In onSaveInstanceState, I am saving my hashmap in a SimpleParcelable class. The code for saving and restoring is :
@Override
protected void onSaveInstanceState(Bundle outState) {
Log.i("mustang", "Saving activity states. size : " + emailsMap.size());
if(emailsMap.size() > 0)
{
outState.putParcelable("parcel", new SimpleParcelable(emailsMap));
}
super.onSaveInstanceState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle state) {
// TODO Auto-generated method stub
Log.i("mustang", "Restoring activity states.");
super.onRestoreInstanceState(state);
SimpleParcelable stateParcel = state.getParcelable("parcel");
emailsMap = (HashMap<String, Message[]>)stateParcel.getEmailsMap();
this.emailsFetched(emailsMap.get("INBOX"), "INBOX", TaskType.NONE);
}
而序列化代碼SimpleParcelable是:
public class SimpleParcelable implements Parcelable{
private final Map<String, Message[]> emailsMap;
public SimpleParcelable(HashMap<String, Message[]> messages)
{
emailsMap = messages;
}
public static final Parcelable.Creator<SimpleParcelable> CREATOR
= new Parcelable.Creator<SimpleParcelable>() {
@Override
public SimpleParcelable createFromParcel(Parcel source) {
Bundle rBundle = source.readBundle();
return new SimpleParcelable((HashMap<String, Message[]>)rBundle.getSerializable("map"));
}
@Override
public SimpleParcelable[] newArray(int size) {
// TODO Auto-generated method stub
return new SimpleParcelable[size];
}
};
@Override
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
Bundle b = new Bundle();
b.putSerializable("map", (HashMap<String, Message[]>)emailsMap);
dest.writeBundle(b);
}
public Map<String, Message[]> getEmailsMap()
{
return emailsMap;
}
}
任何人都可以請指出正在做什麼錯?如果有任何問題,請告訴我如何實現這些編碼和解組代碼?
提前感謝。
從您的評論看來,IMAPMessage似乎沒有實現Parcellable接口。我怎麼能做到這一點?由於我是這個平臺的新手,所以很抱歉這種天真的做法。代碼將有很大的幫助。謝謝 –