【问题标题】:error in read from parcel in Android在Android中从包裹中读取错误
【发布时间】:2023-03-23 17:00:02
【问题描述】:

// 从包裹中读取时出现错误,无法在数组列表中转换 void。

Source Code:






 public class GetTripsByUserIdModel implements Parcelable{

     private static final long serialVersionUID = 1L;
     private String success;
     private String tripId;
     private String tripRequestedBy;
     private String [] tripRequestedTo;
     private String tripAcceptedById;
     private String tripAcceptedByName;
     private String tripConductedBy;
     private String tripStatus;
     private String tripCreatedOn;
     private String tripScheduledBeginOn;
     private String tripScheduledEndOn;
     private String tripStartOn;
     private String tripCompleteOn;
     private String tripNotes;
     private ArrayList<TripDetailModel> tripDetails;

     private boolean mIsSeparator;


     public GetTripsByUserIdModel() {
      // TODO Auto-generated constructor stub
     }

     public GetTripsByUserIdModel(String tripId, String tripRequestedBy,String tripAcceptedById,String tripAcceptedByName,String tripConductedBy
       ,String tripStatus,String tripCreatedOn,String tripScheduledBeginOn,String tripScheduledEndOn,
       String tripStartOn,String tripCompleteOn,String tripNotes,ArrayList<TripDetailModel> tripDetails,boolean mIsSeparator){

       this.tripId = tripId;
       this.tripRequestedBy = tripRequestedBy;
       this.tripAcceptedById = tripAcceptedById;
       this.tripAcceptedByName = tripAcceptedByName;
       this.tripConductedBy = tripConductedBy;
       this.tripStatus = tripStatus;
       this.tripCreatedOn = tripCreatedOn;
       this.tripScheduledBeginOn = tripScheduledBeginOn;
       this.tripScheduledEndOn = tripScheduledEndOn;
       this.tripStartOn = tripStartOn;
       this.tripCompleteOn = tripCompleteOn;
       this.tripNotes = tripNotes;
       this.tripDetails = tripDetails;
       this.mIsSeparator = mIsSeparator;

     }


     public GetTripsByUserIdModel(Parcel in) {
      readFromParcel(in);
     }



     private void readFromParcel(Parcel in) {

           this.success = in.readString();
           this.tripId = in.readString();
           this.tripRequestedBy = in.readString();
           //this.tripRequestedTo = in.readStringArray(tripRequestedTo);
           this.tripAcceptedById = in.readString();
           this.tripAcceptedByName = in.readString();
           this.tripConductedBy = in.readString();
           this.tripStatus = in.readString();
           this.tripCreatedOn = in.readString();
           this.tripScheduledBeginOn = in.readString();
           this.tripScheduledEndOn = in.readString();
           this.tripStartOn = in.readString();
           this.tripCompleteOn = in.readString();
           this.tripNotes = in.readString();
           this.tripDetails = new ArrayList<TripDetailModel>(); 
           this.tripDetails = in.readTypedList(this.tripDetails, TripDetailModel.CREATOR);


        }

    }

// 在读取最后一行的“in.readTypedList”时。它给出错误无法将 void 转换为 ArrayList()。

//Please suggest any mistake i am doing.

请解决

【问题讨论】:

  • in.readTypedList 您将 this.tripDetails 作为参数传递,那么为什么要将 in.readTypedList 的返回值再次分配给 this.tripDetails。尝试删除分配 this.tripDetails = in.readTypedList(这.tr...stackoverflow.com/questions/6774645/…

标签: android parcelable


【解决方案1】:

public final void readTypedList (List list, Creator c)。 readTypedList 的返回类型为 void。

http://developer.android.com/reference/android/os/Parcel.html#readTypedList(java.util.List, android.os.Parcelable.Creator)

private void readFromParcel(Parcel in) {

           this.success = in.readString();
           this.tripId = in.readString();
           this.tripRequestedBy = in.readString();
           //this.tripRequestedTo = in.readStringArray(tripRequestedTo);
           this.tripAcceptedById = in.readString();
           this.tripAcceptedByName = in.readString();
           this.tripConductedBy = in.readString();
           this.tripStatus = in.readString();
           this.tripCreatedOn = in.readString();
           this.tripScheduledBeginOn = in.readString();
           this.tripScheduledEndOn = in.readString();
           this.tripStartOn = in.readString();
           this.tripCompleteOn = in.readString();
           this.tripNotes = in.readString();
           this.tripDetails = new ArrayList<TripDetailModel>(); 
           /*this.tripDetails = in.readTypedList(this.tripDetails, TripDetailModel.CREATOR);*/

           in.readTypedList(this.tripDetails, TripDetailModel.CREATOR);


        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2022-01-25
    相关资源
    最近更新 更多