未经检查的转换:'java.io.Serializable' 到 'java.util.

未经检查的转换:'java.io.Serialized' 到 '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.Serialized' 到 'java.util.ArrayList' 检查信息:向编译器发出未经检查的警告的位置发出信号,例如:


void f(HashMap map) { map.put("key", "value"); }


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


呼如林
浏览 120回答 1
1回答

开满天机

您的模型类 Department 应该实现如下所示的 Selializedpublic class Department implements Serializable {private String itemName;public Department(String itemName) {&nbsp; &nbsp; &nbsp; &nbsp; this.itemName = itemName;&nbsp; &nbsp; }&nbsp;String getItemName() {&nbsp; &nbsp; &nbsp; &nbsp; return itemName;&nbsp; &nbsp; }&nbsp; &nbsp; void setItemName(String itemName) {&nbsp; &nbsp; &nbsp; &nbsp; this.itemName = itemName;&nbsp; &nbsp; }}希望它能起作用。请尝试一下
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java