我想将自定义模型表单片段传递给另一个片段。我的模型是:
public class AddressBookModel implements Serializable {
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getReion() {
return reion;
}
public void setReion(String reion) {
this.reion = reion;
}
public String getLandlineNo() {
return landlineNo;
}
public void setLandlineNo(String landlineNo) {
this.landlineNo = landlineNo;
}
public String getMobileno() {
return mobileno;
}
public void setMobileno(String mobileno) {
this.mobileno = mobileno;
}
public String getPrifix() {
return prifix;
}
public void setPrifix(String prifix) {
this.prifix = prifix;
}
String firstname;
String lastname;
String country;
String street;
String pincode;
String city;
String reion;
String landlineNo;
String mobileno;
String prifix;
}
和另一个模型类是
public class OrderDataModel implements Serializable{
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public ArrayList<ProductBuyDataModel> getbuyProductDetail() {
return buyProductDetail;
}
public void setbuyProductDetail(ArrayList<ProductBuyDataModel> productBuyDataModelsArraylist) {
this.buyProductDetail = productBuyDataModelsArraylist;
}
String phoneno;
public String getPhoneno() {
return phoneno;
}
public void setPhoneno(String phoneno) {
this.phoneno = phoneno;
}
String userId,emailAddress;
ArrayList<ProductBuyDataModel> buyProductDetail;
public AddressBookModel getShipAddDetail() {
return shipAddDetail;
}
public void setShipAddDetail(AddressBookModel shipAddDetail) {
this.shipAddDetail = shipAddDetail;
}
public AddressBookModel getBillAddDetail() {
return billAddDetail;
}
public void setBillAddDetail(AddressBookModel billAddDetail) {
this.billAddDetail = billAddDetail;
}
AddressBookModel shipAddDetail,billAddDetail;
}
它成功地将数据传输到片段,但之后它显示错误
RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.laxmikantbolya.shreenamokar.Model.OrderDataModel)
我不知道发送数据后出现错误的原因。我使用OrderDataModel 用于传递数据。它包含另一个模型类作为变量。 我可以轻松发送简单的单一模型。但我传递一个对象有问题 包含另一个对象。
我不知道为什么&#34; Parcelable遇到IOException&#34;即使我不在我的模型列表中的任何地方使用parcealble。
Logcat输出
09-07 06:16:56.620 18732-18732/com.example.laxmikantbolya.shreenamokar E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.laxmikantbolya.shreenamokar, PID: 18732
java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.example.laxmikantbolya.shreenamokar.Model.OrderDataModel)
at android.os.Parcel.writeSerializable(Parcel.java:1388)
at android.os.Parcel.writeValue(Parcel.java:1335)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.FragmentState.writeToParcel(Fragment.java:138)
at android.os.Parcel.writeTypedArray(Parcel.java:1191)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:376)
at android.os.Parcel.writeParcelable(Parcel.java:1357)
at android.os.Parcel.writeValue(Parcel.java:1262)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2884)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3261)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.io.NotSerializableException: com.example.laxmikantbolya.shreenamokar.Model.ProductBuyDataModel
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.util.ArrayList.writeObject(ArrayList.java:648)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1033)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1383)
at android.os.Parcel.writeValue(Parcel.java:1335)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.FragmentState.writeToParcel(Fragment.java:138)
at android.os.Parcel.writeTypedArray(Parcel.java:1191)
at android.app.FragmentManagerState.writeToParcel(FragmentManager.java:376)
at android.os.Parcel.writeParcelable(Parcel.java:1357)
at android.os.Parcel.writeValue(Parcel.java:1262)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2884)
at android.app.ActivityThread$StopInfo.run(ActivityThread.java:3261)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
程序是
for (int i =0;i<buynowModelList.size();i++){
ProductBuyDataModel productBuyDataModel = new ProductBuyDataModel();
productBuyDataModel.setPrductId(String.valueOf(buynowModelList.get(i).getProductId()));
productBuyDataModel.setQuantity(String.valueOf(buynowModelList.get(i).getQuantity()));
productBuyDataModelArrayList.add(productBuyDataModel);
}
HashMap<String,String> hashMaploginDetail =sessionManager.getUserDetails();
orderDataModel.setbuyProductDetail(productBuyDataModelArrayList);
orderDataModel.setUserId(hashMaploginDetail.get(SessionManager.KEY_UserIdLOGin));
orderDataModel.setEmailAddress(hashMaploginDetail.get(SessionManager.KEY_EmailLOGin));
orderDataModel.setPhoneno(hashMaploginDetail.get(SessionManager.KEY_PhoneNO));
bundle.putSerializable("buyNowData",orderDataModel);
PlaceOrderAddFragment placeOrderAddFragment =new PlaceOrderAddFragment();
placeOrderAddFragment.setArguments(bundle);
mActivity.getFragmentManager().beginTransaction().replace(R.id.buynow_frame,placeOrderAddFragment,TAG).addToBackStack(null).commit();
或将其作为
if (bundle.getSerializable("buyNowData")!=null){
orderDataModel = (OrderDataModel) bundle.getSerializable("buyNowData");
}
我收到了complet数据。但之后它显示我的错误和应用程序崩溃。
我尽可能地谷歌,但我发现只有简单的模型才能通过。他们对我没有帮助 请发给我任何可以帮助我的链接。
答案 0 :(得分:0)
对于传递模型对象,那么所有内部模型都应该使用Serializable实现。所以,请检查我在OrderDataModel类中看到名为“ProductBuyDataModel”的另一个数据模型。确保它也使用Serialzeable实现。
希望如此,这可能有所帮助!