天天看點

java.lang.UnsupportedOperationException

原代碼:

if(adminTeacherInfo.getTeaClass()!=null){
    String[] strArr = adminTeacherInfo.getTeaClass().split(",");
    List<String> stringList = Arrays.asList(strArr);
    if (!stringList .contains(classId)) {
        stringList .add(classId);
        for (String s : stringList) {
            s = s + ",";
            adminTeacherInfo.setTeaClass(s+",");
            adminTeacherInfoService.update(adminTeacherInfo);
        }
    }      

發生在數組轉list ,Arrays.asList(數組) 這是由Arrays.asList() 傳回的市Arrays的内部類ArrayList, 而不是java.util.ArrayList 

改成:

if(adminTeacherInfo.getTeaClass()!=null){
    String[] strArr = adminTeacherInfo.getTeaClass().split(",");
    List<String> stringList = Arrays.asList(strArr);
    List arrList = new ArrayList(stringList);
    if (!arrList.contains(classId)) {
        arrList.add(classId);
        for (String s : stringList) {
            s = s + ",";
            adminTeacherInfo.setTeaClass(s+",");
            adminTeacherInfoService.update(adminTeacherInfo);
        }
    }