未经检查的类型转换:从'java.io.Serializable'到'java.util.ArrayList <com.icresp.campex.wmo.Model.Department>'

时间:2019-09-17 10:12:26

标签: java android arrays android-studio android-intent

未经检查的演员:'java.io.Serializable'到'java.util.ArrayList'

我的代码是这样的:

Activity.java

ArrayList<Department> departments = new ArrayList<>();

Intent i = getIntent();
departments = (ArrayList<Department>) i.getSerializableExtra("DepartmentList");

Department.java

public class Department implements Serializable {
    private int department_id;
    private String dept_name;
    private ArrayList<Course> courses;
    private ArrayList<Batch>batches;

    public Department() {
    }

    public ArrayList<Batch> getBatches() {
        return batches;
    }

    public void setBatches(ArrayList<Batch> batches) {
        this.batches = batches;
    }

    public int getDepartment_id() {
        return department_id;
    }

    public void setDepartment_id(int department_id) {
        this.department_id = department_id;
    }

    public String getDept_name() {
        return dept_name;
    }

    public void setDept_name(String dept_name) {
        this.dept_name = dept_name;
    }

    public ArrayList<Course> getCourses() {
        return courses;
    }

    public void setCourses(ArrayList<Course> courses) {
        this.courses = courses;
    }

    @Override
    public String toString() {
        return dept_name;
    }

}

该应用程序运行良好,但是我收到以下消息:

  

未经检查的强制转换:从'java.io.Serializable'到'java.util.ArrayList'检查信息:指示编译器发出未经检查的警告的位置,例如:

     

void f(HashMap地图){           map.put(“ key”,“ value”);         }

     

提示:将-Xlint:unchecked传递给javac以获取更多详细信息。

1 个答案:

答案 0 :(得分:0)

您的模型课部门应实现以下Selializable

public class Department implements Serializable {
private String itemName;
public Department(String itemName) {
        this.itemName = itemName;
    }
 String getItemName() {
        return itemName;
    }

    void setItemName(String itemName) {
        this.itemName = itemName;
    }
}

希望它会起作用。请尝试