如何在android中访问Serializable对象

时间:2012-11-12 04:19:12

标签: android android-intent

我使用Serializable接口将用户定义的数据从一个活动发送到另一个活动。

这是我的代码:

TasksheetData[] alltasks = new TasksheetData();
Intent in=new Intent(TaskSheetList.this, TaskDetails.class);
in.putExtra("TaskSheetData", alltasks);

在其他活动中,我正在访问此对象,如:

TasksheetData tData =  (TasksheetData) getIntent().getSerializableExtra("TaskSheetData");

这是我的TasksheetData类

@SuppressWarnings("serial")
public class TasksheetData implements Serializable {

    private int TaskID;

    private int AttendantID;
    private String  AttendentName;

    private String  ReservationID;
    private String  ResStatusCode;

    private int InspectionStartedById;
    private String  HKStatusCode;

    private int FOStatusID;
    private String  FOStatusCode;

    private int JobStatusID;
    private String  JobStatusCode;

    private int LocationID;
    private String  LocationName;

    private int RoomTypeID;
    private String  RoomType;

    private int SectionID;

    private String  GuestID;
    private String  GuestName;
    private String  VIPCode;
    private String  Pax;
    private String  ArrivalTime;
    private String  CheckInTime;
    private String  CheckOutTime;

    private String  QueueSince;

    private Trace[] arrTraces;
    private String  Specials;

    private String  ReservationComments;
    private String SupervisorComments;

    private String  HKNotes;
    private String  TaskSheetName;

    private int StandardCleaningTime;

    private int AttendantPriority;
    private String   SupervisorPriority;

    private String  TaskStartTime;
    private String  TaskEndTime;

    private String  TasksheetInstruction;

    private String localJobStatusCode;
    private Boolean isSynch;
    private String   credit;
    private String   RemainingTimeSec;

    private String   TaskTypeId;
    private String   AttendantCLTypeId, SupervisorCLTypeId;
    private String TritonLocationID;

    private String   PendingTritonJob;
    private Boolean         isDiscrepancy, InspectionStatus, IsTaskInspected;

    public int getTaskID() {
        return TaskID;
    }
    public void setTaskID(int taskID) {
        TaskID = taskID;
    }
    public int getAttendantID() {
        return AttendantID;
    }
    public void setAttendantID(int attendantID) {
        AttendantID = attendantID;
    }
    public String getAttendentName() {
        return AttendentName;
    }
    public void setAttendentName(String attendentName) {
        AttendentName = attendentName;
    }
    public String getReservationID() {
        return ReservationID;
    }
    public void setReservationID(String reservationID) {
        ReservationID = reservationID;
    }
    public String getResStatusCode() {
        return ResStatusCode;
    }
    public void setResStatusCode(String resStatusCode) {
        ResStatusCode = resStatusCode;
    }
    public int getInspectionStartedById() {
        return InspectionStartedById;
    }
    public void setInspectionStartedById(int inspectionStartedById) {
        InspectionStartedById = inspectionStartedById;
    }
    public String getHKStatusCode() {
        return HKStatusCode;
    }
    public void setHKStatusCode(String hKStatusCode) {
        HKStatusCode = hKStatusCode;
    }
    public int getFOStatusID() {
        return FOStatusID;
    }
    public void setFOStatusID(int fOStatusID) {
        FOStatusID = fOStatusID;
    }
    public String getFOStatusCode() {
        return FOStatusCode;
    }
    public void setFOStatusCode(String fOStatusCode) {
        FOStatusCode = fOStatusCode;
    }
    public int getJobStatusID() {
        return JobStatusID;
    }
    public void setJobStatusID(int jobStatusID) {
        JobStatusID = jobStatusID;
    }
    public String getJobStatusCode() {
        return JobStatusCode;
    }
    public void setJobStatusCode(String jobStatusCode) {
        JobStatusCode = jobStatusCode;
    }
    public int getLocationID() {
        return LocationID;
    }
    public void setLocationID(int locationID) {
        LocationID = locationID;
    }
    public String getLocationName() {
        return LocationName;
    }
    public void setLocationName(String locationName) {
        LocationName = locationName;
    }
    public int getRoomTypeID() {
        return RoomTypeID;
    }
    public void setRoomTypeID(int roomTypeID) {
        RoomTypeID = roomTypeID;
    }
    public String getRoomType() {
        return RoomType;
    }
    public void setRoomType(String roomType) {
        RoomType = roomType;
    }
    public int getSectionID() {
        return SectionID;
    }
    public void setSectionID(int sectionID) {
        SectionID = sectionID;
    }
    public String getGuestID() {
        return GuestID;
    }
    public void setGuestID(String guestID) {
        GuestID = guestID;
    }
    public String getGuestName() {
        return GuestName;
    }
    public void setGuestName(String guestName) {
        GuestName = guestName;
    }
    public String getVIPCode() {
        return VIPCode;
    }
    public void setVIPCode(String vIPCode) {
        VIPCode = vIPCode;
    }
    public String getPax() {
        return Pax;
    }
    public void setPax(String pax) {
        Pax = pax;
    }
    public String getArrivalTime() {
        return ArrivalTime;
    }
    public void setArrivalTime(String arrivalTime) {
        ArrivalTime = arrivalTime;
    }
    public String getCheckInTime() {
        return CheckInTime;
    }
    public void setCheckInTime(String checkInTime) {
        CheckInTime = checkInTime;
    }
    public String getCheckOutTime() {
        return CheckOutTime;
    }
    public void setCheckOutTime(String checkOutTime) {
        CheckOutTime = checkOutTime;
    }
    public String getQueueSince() {
        return QueueSince;
    }
    public void setQueueSince(String queueSince) {
        QueueSince = queueSince;
    }
    public Trace[] getArrTraces() {
        return arrTraces;
    }
    public void setArrTraces(Trace[] arrTraces) {
        this.arrTraces = arrTraces;
    }
    public String getSpecials() {
        return Specials;
    }
    public void setSpecials(String specials) {
        Specials = specials;
    }
    public String getReservationComments() {
        return ReservationComments;
    }
    public void setReservationComments(String reservationComments) {
        ReservationComments = reservationComments;
    }
    public String getSupervisorComments() {
        return SupervisorComments;
    }
    public void setSupervisorComments(String supervisorComments) {
        SupervisorComments = supervisorComments;
    }
    public String getHKNotes() {
        return HKNotes;
    }
    public void setHKNotes(String hKNotes) {
        HKNotes = hKNotes;
    }
    public String getTaskSheetName() {
        return TaskSheetName;
    }
    public void setTaskSheetName(String taskSheetName) {
        TaskSheetName = taskSheetName;
    }
    public int getStandardCleaningTime() {
        return StandardCleaningTime;
    }
    public void setStandardCleaningTime(int standardCleaningTime) {
        StandardCleaningTime = standardCleaningTime;
    }
    public int getAttendantPriority() {
        return AttendantPriority;
    }
    public void setAttendantPriority(int attendantPriority) {
        AttendantPriority = attendantPriority;
    }
    public String getSupervisorPriority() {
        return SupervisorPriority;
    }
    public void setSupervisorPriority(String supervisorPriority) {
        SupervisorPriority = supervisorPriority;
    }
    public String getTaskStartTime() {
        return TaskStartTime;
    }
    public void setTaskStartTime(String taskStartTime) {
        TaskStartTime = taskStartTime;
    }
    public String getTaskEndTime() {
        return TaskEndTime;
    }
    public void setTaskEndTime(String taskEndTime) {
        TaskEndTime = taskEndTime;
    }
    public String getTasksheetInstruction() {
        return TasksheetInstruction;
    }
    public void setTasksheetInstruction(String tasksheetInstruction) {
        TasksheetInstruction = tasksheetInstruction;
    }
    public String getLocalJobStatusCode() {
        return localJobStatusCode;
    }
    public void setLocalJobStatusCode(String localJobStatusCode) {
        this.localJobStatusCode = localJobStatusCode;
    }
    public Boolean getIsSynch() {
        return isSynch;
    }
    public void setIsSynch(Boolean isSynch) {
        this.isSynch = isSynch;
    }
    public String getCredit() {
        return credit;
    }
    public void setCredit(String credit) {
        this.credit = credit;
    }
    public String getRemainingTimeSec() {
        return RemainingTimeSec;
    }
    public void setRemainingTimeSec(String remainingTimeSec) {
        RemainingTimeSec = remainingTimeSec;
    }
    public String getTaskTypeId() {
        return TaskTypeId;
    }
    public void setTaskTypeId(String taskTypeId) {
        TaskTypeId = taskTypeId;
    }
    public String getAttendantCLTypeId() {
        return AttendantCLTypeId;
    }
    public void setAttendantCLTypeId(String attendantCLTypeId) {
        AttendantCLTypeId = attendantCLTypeId;
    }
    public String getSupervisorCLTypeId() {
        return SupervisorCLTypeId;
    }
    public void setSupervisorCLTypeId(String supervisorCLTypeId) {
        SupervisorCLTypeId = supervisorCLTypeId;
    }
    public String getTritonLocationID() {
        return TritonLocationID;
    }
    public void setTritonLocationID(String tritonLocationID) {
        TritonLocationID = tritonLocationID;
    }
    public String getPendingTritonJob() {
        return PendingTritonJob;
    }
    public void setPendingTritonJob(String pendingTritonJob) {
        PendingTritonJob = pendingTritonJob;
    }
    public Boolean getIsDiscrepancy() {
        return isDiscrepancy;
    }
    public void setIsDiscrepancy(Boolean isDiscrepancy) {
        this.isDiscrepancy = isDiscrepancy;
    }
    public Boolean getInspectionStatus() {
        return InspectionStatus;
    }
    public void setInspectionStatus(Boolean inspectionStatus) {
        InspectionStatus = inspectionStatus;
    }
    public Boolean getIsTaskInspected() {
        return IsTaskInspected;
    }
    public void setIsTaskInspected(Boolean isTaskInspected) {
        IsTaskInspected = isTaskInspected;
    }
}

但是当我尝试将它强制转换为我的数据对象时,它会给出类强制转换异常。

请帮我解决这个问题?

2 个答案:

答案 0 :(得分:1)

您正在放入一个数组并期待一个对象。另外,请使用ArrayList serializable。{/ p>

答案 1 :(得分:0)

不确定您的TasksheetData课程是什么,但也许您应该使用alltasks代替ParcelableArray

结帐this

您的TasksheetData数组绝对不是一个Serializable类的实例...