-1

I am trying to copy the Right portion of frame data. The image below could be useful. Data is in single array form.

Picture

I want to get single array right column of data frame. I am getting "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1000". I am not sure what's wrong.

Exception in thread "main" 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;

              }

          }
    }

}
Engineero
  • 10,387
  • 3
  • 41
  • 65
ZeSamPam
  • 13
  • 2

1 Answers1

0

The line

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

sets the value of sourceArray to 1000 on the final iteration of the for loop. You then try to access element 1000 of the data array

hwData[i] = data[sourceArray];

However the data array only has 1000 elements

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

So the largest index is only 999, which is why you get the ArrayIndexOutOfBounds Exception. Fix your loop so that the value of sourceArray is never greater than 999.