迭代List <long> </long>时抛出异常

时间:2015-03-04 11:57:48

标签: java

我试图迭代长类型的列表,但我得到: -

java.lang.String cannot be cast to java.lang.Long

这是我的代码: -

for(Long organid : patientTypesBean.getOrganList()){ // Exception in this line
 //... 
}

patientTypesBean.getOrganList()返回Long类型的arrayList。我甚至尝试循环,但同样的问题

for(int i=0;i<patientTypesBean.getOrganList().size();i++){
        System.out.println("--------------Value is---->"+patientTypesBean.getOrganList().get(i));
        patientOrganEntity.getOrganListID().setParameterListID(patientTypesBean.getOrganList().get(i)); // here i get exception
    }
寻求帮助。提前谢谢

编辑: -

List<Long> organList = new ArrayList<Long>();
public List<Long> getOrganList() {
    return organList;
}

public void setOrganList(List<Long> organList) {
    this.organList = organList;
}

1 个答案:

答案 0 :(得分:0)

你可以尝试一次,

for(int i=0;i<patientTypesBean.getOrganList().size();i++){
    Long organ = Long.valueOf(patientTypesBean.getOrganList().get(i));
    patientOrganEntity.getOrganListID().setParameterListID(organ);
}