Runtime error in a method
I get runtime error in a method, I have tired for hours to figure it out but no positive progress so far.
Code:
public static String[][] produceKey () throws Exception
{
StringBuilder[][] key = new StringBuilder[theChars.length + 2][100];
char[] encryptChar = {'§', '¥', '$'};
//All the "a" characters will be replaced with one of the chars in encryptChar array.
for (int q = 0; q < key.length; q++)
{
for (int w = 0; w < 100; w++)
key[q][w] = new StringBuilder ("|aaaaaaaaaa|");
}
//Time to generate the key code!
for (int i = 0; i < key.length; i++)
{
FLoop:
for (int j = 0; j < 100; j++)
{
for (int charPosition = 1; charPosition <= 10; charPosition++)
{
key[i][j].setCharAt (charPosition, encryptChar[(int) (3 * Math.random())]);
}
if (j == 0 && i == 0)
continue FLoop; //There is nothing to compare with if i and j is zero
//Here starts a check algoritm, to make sure there is no duplicated code
for (int iC = 0; iC < i; iC++)
{
for (int jC = 0; jC < j; jC++)
{
if (key[i][j].equals (key[iC][jC]))
{
j--;
continue FLoop;
}
}
}
}
}
//Convert key to a string array
String[][] rkey = new String[key.length][100];
for (int n = 0; n < rkey.length; n++)
{
for (int m = 0; m < 100; m++)
rkey[n][m] = new String (key[n][m].toString ());
}
//Print the key into a file
File fil = new File ("cryptKey.key");
PrintWriter fout = new PrintWriter (fil);
for (int p = 0; p < rkey.length; p++)
{
for (int o = 0; o < 100; o++)
fout.println (rkey[p][o].toString ());
}
fout.close ();
//DEBUGGING
System.out.println (key[10][5]);
System.out.println (key[theChars.length + 2][4]);//HERE IS WHERE THE PROGRAM CRASH
return rkey;
}
Code:
public static char[] theChars =
{'!', '\'', '#', '¤', '%', '&', '/', '(', ')',
'=', '?', '`', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', '+', '´', '‰', '½', '@',
'£', '„', '€', '{', '[', ']', '}', '\\', 'q',
'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'å', '¨', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U',
'I', 'O', 'P', 'Å', '^', '~', 'a', 's', 'd',
'f', 'g', 'h', 'j', 'k', 'l', 'ö', 'ä', '\'',
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
'Ö', 'Ä', '*', '<', 'z', 'x', 'c', 'v', 'b',
'n', 'm', ',', '.', '-', '>', 'Z', 'X', 'C',
'V', 'B', 'N', 'M', ';', ':', '_', '…', 'µ',
'ª', '©', '¨', '¦', 'Œ', '¢', '¡', ' ', ' ',
'«', '¬', '*', '®', '¯', '°', '±', '²', '³',
'¶', '·', '¸', '¹', 'º', '»', '¼', '¾', '¿',
'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È',
'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ',
'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú',
'Û', 'Ü', 'Ý', 'Þ', 'ß', 'à', 'á', 'â', 'ã',
'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì',
'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ',
'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ',
'ÿ', '†', 'ƒ', '‡', 'Š', 'Ž', '×'};
And the exception
http://img703.imageshack.us/img703/1702/errorsa.png
theChars arrays length is 205.