gpt4 book ai didi

java - 迭代 List 时发生类转换异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:06:11 25 4
gpt4 key购买 nike

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

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

这是我的代码:--

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

patentTypesBean.getOrganList() 返回 Long 类型的 arrayList。我什至尝试 for 循环但同样的问题

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;
}

最佳答案

你能尝试一下吗,

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

关于java - 迭代 List<Long> 时发生类转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28853882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com