[英]hibernate - Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
[英]Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
我在执行此代码时获得了此异常?
public static void main(String[] args) throws SQLException {
professeur f = new professeur();
ArrayList<Integer> arl =new ArrayList<Integer>();
int k=0;
etudiant e = new etudiant();
List<etudiant> list = e.getAll();
List<professeur> l = f.getAll1();
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < l.size(); j++) {
if (list.get(j).getIde()==l.get(i).getIdp()) {
k=list.get(i).getIde();
System.out.println(list.get(i).getNome());
}
break;
}
professeur p=new professeur();
List <professeur> c= p.findAllbyID(k);
System.out.println(c.get(i).getNomp());}
}
}
看来您的索引已切换。
由于i
遍历list
的索引和j
遍历l
的索引,因此应为:
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < l.size(); j++) {
if (list.get(i).getIde()==l.get(j).getIdp()) { // i and j were switched
// on this line
k=list.get(i).getIde();
System.out.println(list.get(i).getNome());
}
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.