My homework is to create a QRcode generator and I am stuck at creating the two Timing Pattern of the QR code base matrix. scheme of a QR code So I am looking for a way to create a checkboard using a 2D array, then use only the first and the first column to fill two other array with successively a black dot, a white dot, a black dot and so on. Then I fill the horizontal Timing Pattern Array with the first row and the vertical Timing Pattern with the first column. For this I use two methods: 1)Creation the checkboard and "filling" of the Timing Pattern, and 2)Declaration of the two TimingPatern arrays and then fill them
This is the code I have created :
//method to create the checkboard
public static int[][] timingPatternFilling (int[][] timingPattern) {
for (int i=0;i<timingPattern[0].length-1;i++)
for (int j=0;j<=timingPattern[1].length-1;j++)
if (((i%2==0)&&(j%2==0))||((i%2==1)&&(j%2==1))) {
timingPattern[i][j] = B;
System.out.print(timingPattern[i][j]);
}
else {
timingPattern[i][j] = W;
System.out.print(timingPattern[i][j]);
}
System.out.println();
return timingPattern;
}
//method to create the Timing Pattern
public static void addTimingPatterns(int[][] matrix) {
// creation of the Timing Pattern (The calculation "matrix[1].length-2*(finderPatternSize+1)" allow to calculate the timingPattern length depending on the size of the matrix minus 2 times the size of the finder Pattern size
int timingPatternVertical[][] = new int [matrix[0].length-(2*whiteSquareSize)][timingPatternLength];
int timingPatternHorizontal[][] = new int [timingPatternLength][matrix[1].length-(2*whiteSquareSize)];
//filling with the Black Pattern
timingPatternFilling(timingPatternVertical);
timingPatternFilling(timingPatternHorizontal);
So when I tried to run ths code I get the following error message : java.lang.ArrayIndexOutOfBoundsException. I think this related to the length of the arrays.
How can I solve this?