2017-09-08 6 views
-1

프레임 데이터의 오른쪽 부분을 복사하려고합니다. 아래 이미지가 유용 할 수 있습니다. 데이터는 단일 배열 형식입니다.배열의 특정 요소를 다른 배열에 복사

Picture

나는 데이터 프레임의 단일 배열 오른쪽 열을 싶어. "스레드의 예외"메인 "java.lang.ArrayIndexOutOfBoundsException: 1000"이 나타납니다. 나는 무엇이 잘못되었는지 확신하지 못한다. 스레드 "메인"java.lang.ArrayIndexOutOfBoundsException에

예외 : 1000

public static void main(String args[]) { 
    int height=10; 
    int width = 100; 
    int data[]= new int [height*width]; 
    int multipiler=0; 
    int counter =1; 
    int hwAssistWidth=5; 
    int hwData[] = new int[hwAssistWidth*height]; 
    int countTheFrame = 0; 
    int countTheFrame1 = 0; 
    int sourceArray; 

    for(int i=0; i<hwAssistWidth*height; i++){ 
      sourceArray = ((width-hwAssistWidth)+width*multipiler)+counter++; 
      hwData[i] = data[sourceArray]; 


      if (counter==hwAssistWidth+1){ 
       counter =1; 
       multipiler++; 
       if(multipiler==height){ 
        break; 

       } 

      } 
    } 

} 
+0

프로그램을 디버그 했습니까? – f1sh

+0

예, 했어요. 데이터 배열 내부의 값은 무시하십시오. – ZeSamPam

+0

색인에 배열 데이터가 없기 때문에 –

답변

0

라인

sourceArray = ((width-hwAssistWidth)+width*multipiler)+counter++; 

은 최종 반복에서 1000 sourceArray의 값을 설정 for 루프. 데이터 배열이 1000 개 요소

int height=10; 
int width = 100; 
int data[]= new int [height*width]; 

있다 그러나 당신은 그래서 가장 큰 인덱스는 ArrayIndexOutOfBounds 예외를 얻을 이유입니다 만 999 인 데이터 배열

hwData[i] = data[sourceArray]; 

의 요소 (1000)에 액세스하려고합니다. sourceArray의 값이 999보다 커지지 않도록 루프를 수정하십시오.

+0

@ JoshuaNewHouse. 감사합니다. 작동했습니다. – ZeSamPam

+0

문제 없습니다. 귀하의 질문에 대한 답변이 있으면 답변으로 표시해야합니다. –