1
클래스 "일정"이 있습니다. 코드가 실행될 때마다자바 객체 복사 중, 배열 색인이 범위를 벗어났습니다.
public class schedule {
public int P;
public int K;
Vector<Vector<element>> r;
public schedule(int p, int k) {
this.P = p;
this.K = k;
r = new Vector<Vector<element>>(5 * P);
for (int i = 0; i < 5 * p; i++) {
Vector<element> v = new Vector<element>();
r.add(v);
}
}
schedule(schedule s){
P = s.P;
K = s.K;
r = s.r;
}
public ArrayList<schedule> getSuccessors() {
ArrayList<schedule> routine;
routine = new ArrayList<schedule>();
schedule temp= new schedule(this);
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < r.get(i).size(); j++) {
for (int k = 1; k < r.size(); k++) {
//System.out.println(r.elementAt(i).size());
//System.out.println(r.elementAt(j).size());
//System.out.println("credit "+ r.elementAt(i).elementAt(j).credit);
if (!r.elementAt(k).contains(r.elementAt(i).elementAt(j))) {
temp.r = r;
temp.r.elementAt(k).add(r.elementAt(i).elementAt(j));
temp.r.get(i).remove(j);
}
}
}
routine.add(temp);
}
return routine;
}
}
내가 java.lang.ArrayIndexOutOfBoundsException 얻을 : getSuccessors에서 0> = 0 오류 메시지() method.Any의 도움을 크게 환영합니다.
질문과 관련이 없지만 Vector를 사용해야하는 특별한 이유가 있습니까? 스레드 안전 구현이 필요하지 않은 경우 대신 ArrayList (https://docs.oracle.com/javase/9/docs/api/java/util/Vector.html)를 사용하는 것이 좋습니다. – Boris