Parcelable encountered IOException writing serializable object?
我得到"parcelable在编写可序列化对象时遇到IOException"错误。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public void onClick(View v) { tvResult.setText("Povezivanje s bazom u tijeku..."); Intent i = new Intent("android.intent.action.MAINACTIVITY"); Details details = new Details(); details.host=etHost.getText().toString(); details.user=etUsername.getText().toString(); details.pass=etPass.getText().toString(); details.database=etBaza.getText().toString(); new GetData(tvResult).execute(""); Bundle bundle = new Bundle(); bundle.putSerializable("Detalji", details); i.putExtras(bundle); startActivity(i); } |
这也是我的细节课程:
1 2 3 4 5 6 7 8 9 | public class Details implements Serializable { private static final long serialVersionUID = 1L; private String host; private String pass; private String user; private String database; } |
号
一切正常,直到
在你overridden writetoparcel细节级和readfromparcel?
1 2 3 | @Override public void writeToParcel(Parcel dest, int flags) { } |
需要实现的细节,如果你想parceleable护照通过intents复杂的对象。
一流的细节需要在它自己的文件parcelable你都没有实施。
你有你的
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public class Details implements Serializable, Parcelable { private static final long serialVersionUID = 1L; private String host; private String pass; private String user; private String database; public Details(Parcel in){ this.host = in.readString(); this.pass = in.readString(); this.user = in.readString(); this.database = in.readString(); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.host); dest.writeString(this.pass); dest.writeString(this.user); dest.writeString(this.database); } public static final Parcelable.Creator<Details> CREATOR = new Parcelable.Creator<Details>() { public Details createFromParcel(Parcel in) { return new Details(in); } public Details[] newArray(int size) { return new Details[size]; } }; } |
现在我想写的东西是要为你工作,但我不是100%肯定要做一些阅读,所以从这里:aditional
- prasanta-paul.blogspot.com http:/ / / / / android-parcelable-example.html 2010年06
- techdroid.kbeanie.com http:/ / / / / parcelable-how-to-do-that-in-android.html 2010年06